package
Wrap read/write/transform functions into streams
npm install stream-wrapperGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Drop-in replacement for the core stream
that allows you to create streams from read/write functions.
npm install stream-wrapperAll streams create are stream2 streams
var stream = require('stream-wrapper');
var rs = stream.readable(function read(size) {
this.push(new Buffer('hello world'));
});If you don't have a read function just omit it
var rs = stream.readable();
rs.push(new Buffer('hello world'));The Readable prototype is exposed through stream.Readable.
var stream = require('stream-wrapper');
var ws = stream.writable(function writable(chunk, enc, callback) {
console.log('writing', chunk);
callback();
});The Writable prototype is exposed through stream.Writable.
var stream = require('stream-wrapper');
var ds = stream.duplex(function read() {
this.push(new Buffer('hello world'));
}, function write(chunk, enc, callback) {
console.log('writing', chunk);
callback();
});The Duplex prototype is exposed through stream.Duplex
var stream = require('stream-wrapper');
var ts = stream.transform(function transform(chunk, enc, callback) {
this.push(chunk);
callback();
});If you want to add a flush function pass it as the second parameter
var ts = stream.transform(function transform() {
...
}, function flush(callback) {
console.log('now flushing...');
callback();
});The Transform prototype is exposed through stream.Transform
If you want to pass stream options (like objectMode) pass them as the first
parameter to readable, writable, duplex or transform
var rs = stream.readable({objectMode:true}, function read() {
this.push({message:'i am an object'});
});You can change the default options for the stream by calling defaults
// all streams created have objectMode enabled
stream = stream.defaults({objectMode:true});All streams have a .destroy method implemented per default that when called
emits close and sets stream.destroyed = true.
var rs = stream.readable();
rs.on('close', function() {
// rs.destroyed === true
console.log('someone called destroy');
});
rs.destroy();MIT
Estimated unpacked size across 12 packages.
907.1 kB
Includes dependencies.