Skip to content

Compatibility with abstract-level v.2.0.0? #17

Closed
@dehmer

Description

@dehmer

TL;DR: Is level-read-stream v1.1.0 compatible with abstract-level v.2.0.0? If not, is there a similar package which supports Node Streams and is compatible with abstract-level v.2.0.0?

I'm trying to migrate a project to current Level-APIs. The project heavily uses Level (native) for different aspects under Node.js/Electron (with node integration enabled). Besides other stuff, I have a class extending AbstractLevel with an iterator extending AbstractIterator. This class basically uses two sublevels with different value encodings (JSON and Well-known Binar, WKB) to split and merge data between these two sublevels based on same keys.

The implementation is based on the v2.0.0 abstract-level (Promise) API. The AbstractLevel part works like a charm. AbstractIterator when combined with level-read-stream does more or less nothing.

EntryStream seems not to emit any event for the following code:

/**
 * list :: EntryStream -> [{k, v}]
 * @async
 */
const list = stream => new Promise((resolve, reject) => {
  const acc = []
  stream
    .on('data', data => acc.push(data))
    .on('err', reject)
    .on('end', () => resolve(acc))
})

I tried to debug the code for Node.js, but came to no definitive conclusion. It seems that the "handoff" to Readable somehow fails. The iterator itself is producing the correct output for _next().

Good news! Working code ahead:

/**
 * list :: AbstractLevel -> [{k, v}]
 * @async
 */
const list = async db => {
  const acc = []
  for await (const entry of db.iterator()) acc.push(entry)
  return acc
}

So the iterator code might not be broken after all.

If you think that level-read-stream v1.1.0 is indeed compatible with current abstract-level then I happily patch together a minimal repository which demonstrates the issue. In the meantime I'll try to go with for await.

Thanks for your attention and all the good work you put into the Level ecosystem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions