Level Read Stream

2.0.0 · active · verified Wed Apr 22

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`.

Common errors

Warnings

Install

Imports

Quickstart

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);

view raw JSON →