Created
January 17, 2017 21:42
-
-
Save iSkore/0ed785a4e6abd20f4cc3b68865d5bbc7 to your computer and use it in GitHub Desktop.
Streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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