Registry / database / level-read-stream

level-read-stream

JSON →
library2.0.0jsnpmunverified

level-read-stream provides Node.js-style readable streams for abstract-level compatible databases. It allows developers to consume data from a LevelDB-like database as a stream of entries, keys, or values. The current stable version is 2.0.0, which notably supports `abstract-level` v2 and Node.js >=18. The project maintains an active development pace with incremental releases addressing compatibility and adding features like TypeScript types. Key differentiators include its tight integration with the `abstract-level` API, offering `EntryStream`, `KeyStream`, and `ValueStream` for optimized data retrieval. For Web Streams, users are directed to `level-web-stream`.

npm install level-read-stream
INSTALL
IMPORT
SIG · LEVEL-READ-STREAM
L
level-read-stream
databasejavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EntryStream
import { EntryStream } from 'level-read-stream'
const EntryStream = require('level-read-stream').EntryStream
For ESM projects, use named import. CommonJS `require` still works but destructuring is crucial.
KeyStream
import { KeyStream } from 'level-read-stream'
import KeyStream from 'level-read-stream'
All stream classes are named exports. Default import will not work.
ValueStream
import { ValueStream } from 'level-read-stream'
const { ValueStream } = require('level-read-stream')
When using CommonJS, ensure you destructure the specific stream class from the `require` call.

This example demonstrates how to create an `EntryStream` to read key-value pairs from an `abstract-level` database, filter by a starting key (`gte: 'b'`), and pipe the results to a writable stream for processing, logging each entry.

import { EntryStream } from 'level-read-stream'; import { Writable, pipeline } from 'readable-stream'; import { Level } from 'level'; // Assuming 'level' or similar abstract-level implementation async function runExample() { const db = new Level('./mydb'); await db.put('a', '1'); await db.put('b', '2'); await db.put('c', '3'); const src = new EntryStream(db, { gte: 'b' }); const dst = new Writable({ objectMode: true, write(entry, _, next) { console.log('Entry: %s: %s', entry.key, entry.value); next(); } }); // Using pipeline with a callback for error handling and stream completion pipeline(src, dst, (err) => { if (err) { console.error('Pipeline failed.', err); } else { console.log('Pipeline succeeded.'); } db.close(); // Close the database after stream operations }); } runExample().catch(console.error);
Debug
Known issues
breakingVersion 2.0.0 drops support for `abstract-level` v1. Users must upgrade their underlying `abstract-level` implementation to `>=2.0.0`.
fix
Ensure your database package (e.g., `level`, `memdown`) is updated to a version compatible with `abstract-level@2`.
affects: >=2.0.0
breakingVersion 2.0.0 updated its internal `readable-stream` dependency from v3 to v4. While largely compatible, this might introduce subtle behavioral changes or require adjustments if your project relies on specific `readable-stream` v3 internals.
fix
Review your stream pipeline for compatibility with `readable-stream` v4 behavior, especially if you have custom `_read` or `_write` implementations.
affects: >=2.0.0
gotchaFor TypeScript users, in addition to installing `level-read-stream`, you must also install `@types/readable-stream` to get proper type definitions for Node.js's stream API.
fix
Run `npm install --save-dev @types/readable-stream`.
affects: >=1.1.0
gotchaIf migrating from older `levelup` or `level <= 7` versions, consult the `UPGRADING.md` file in the package's GitHub repository for specific migration steps and considerations.
fix
Refer to `https://github.com/Level/read-stream/blob/main/UPGRADING.md` for detailed instructions.
affects: >=1.0.0
gotchaWhile `EntryStream` provides a stream interface, for consuming database entries using `for await...of` syntax, it is generally recommended to directly use `db.iterator()` as it offers a more idiomatic async iteration pattern.
fix
Consider `for await (const entry of db.iterator(options))` instead of piping `EntryStream` for simple async iteration.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: db.iterator is not a function
Attempting to use `level-read-stream` v2.x with an `abstract-level` v1.x compatible database instance.
fix
Upgrade your database package (e.g., `level`, `memdown`) to a version that implements `abstract-level` v2 or higher.
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/level-read-stream/index.js from ... not supported.
Attempting to use `require()` to import `level-read-stream` in an environment configured for pure ESM, or when `level-read-stream` itself becomes pure ESM in a future major version (not currently true for v2).
fix
Change your import statement to `import { EntryStream } from 'level-read-stream';` and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
TypeError: EntryStream is not a constructor
Incorrect import statement when using CommonJS, attempting `const EntryStream = require('level-read-stream')` instead of destructuring.
fix
Use `const { EntryStream } = require('level-read-stream');` to correctly destructure the named export.
TS2307: Cannot find module '@types/readable-stream' or its corresponding type declarations.
Missing TypeScript type definitions for the `readable-stream` package when using `level-read-stream` in a TypeScript project.
fix
Install the types package: `npm install --save-dev @types/readable-stream`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
abstract-levelrequiredRequired as the underlying database interface.
@types/readable-streamoptionalTypeScript type declarations for Node.js readable streams, required when using this library with TypeScript.
Agent activity
10 hits · last 30 days
node
8
Resources
level-read-stream — npm install level-read-stream · libregistry