Skip to content

Instantly share code, notes, and snippets.

@iSkore
Created January 17, 2017 21:42
Show Gist options
  • Save iSkore/0ed785a4e6abd20f4cc3b68865d5bbc7 to your computer and use it in GitHub Desktop.
Save iSkore/0ed785a4e6abd20f4cc3b68865d5bbc7 to your computer and use it in GitHub Desktop.
Streams
class ReadStream
{
constructor( obj, opt = {} )
{
if( Buffer.isBuffer( obj ) || obj === ''+obj )
stream.Readable.call( this, {
highWaterMark: opt.highWaterMark, encoding: opt.encoding
} );
else
stream.Readable.call( this, { objectMode: true } );
this._object = obj;
this.init();
}
init()
{
ReadStream.prototype._read = () => {
this.push( this._object );
this._object = null;
};
}
}
util.inherits( ReadStream, stream.Readable );
let createReadStream = ( obj, opt ) => new ReadStream( obj, opt );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment