rereadable-stream
v1.4.14
Published
A simple standards-based stream that can be read again from begining.
Downloads
34,862
Readme
Re-Readable Stream
The module exposes a Writable stream that you can replay at any given moment to any number of Writable outputs. Think of it as a DVR feature for Node.js streams - one stream can start playing, but others may want to join in at any given point in time and start reading from the begining.
Usage:
const {ReReadable} = require("rereadable-stream");
let rereadable = fs.createReadStream("myfile")
.pipe(new ReReadable(options));
srv.on("connection", (sock) => sock.pipe(rereadable.rewind()));
The module exposes a simple API on as an extension a standard Writable stream:
- tail(count) - the last number of stream chunks will be pushed and then rest of it.
- rewind() - this will stream from the begining of the buffer.
The options are:
- length - 1 million items as standard
- standard Writable stream options
If one of readable stream cannot cope with the speed of other streams drop
events will be emitted to inform about it.
rewound.on("drop", (count) => console.log(`dropped ${count} items`));
Notice: For version 1.0.0 only object streams are well tested. There's no reason why buffer stream should not work, but they won't follow any sensible limits. This will be fixed in 1.2.0.
License
See LICENSE (MIT).
For other licensing options please open an issue or contact the author at opensource (at) signicode.com