level-stream

Persist streams in leveldb.

level-stream

Persist streams in leveldb.

var stream = require('level-stream');
var levelup = require('levelup');
var fs = require('fs');
 
var db = levelup('/tmp/level-stream');
 
fs.createReadStream(__dirname + '/file.txt')
  .pipe(stream(db, 'file'))
  .on('end', function () {
    // file.txt is stored in leveldb now 
    stream(db, 'file').pipe(process.stdout);
  });

Returns a Duplex Stream.

If you start reading from it it replays the stream stored at key. If you write to it it persists written data at key.

Extend db with the db#stream so you can do

db.stream('file')
  • resuming logic: stream(db, 'file', date) should emit all data that was written since date.
  • live streams: stream.live(...) should stay open and emit new data.

With npm do

$ npm install level-stream

(MIT)