Created
April 13, 2016 00:51
-
-
Save ORESoftware/e733e03334d885c9249b81866ed5b9b9 to your computer and use it in GitHub Desktop.
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
var BufferStream = function () { | |
stream.Transform.apply(this, arguments); | |
this.sumanReady = false; | |
this.buffer = []; | |
}; | |
util.inherits(BufferStream, stream.Transform); | |
BufferStream.prototype._transform = function (chunk, encoding, done) { | |
// custom buffering logic | |
// ie. add chunk to this.buffer, check buffer size, etc. | |
if (this.sumanReady) { | |
this.push(chunk ? String(chunk) : null); | |
} | |
else { | |
this.buffer.push(chunk ? String(chunk) : null); | |
} | |
done() | |
}; | |
BufferStream.prototype.pipe = function (destination, options) { | |
var res = BufferStream.super_.prototype.pipe.apply(this, arguments); | |
this.buffer.forEach(function (b) { | |
res.write(String(b)); | |
}); | |
this.sumanReady = true; | |
return res; | |
}; | |
// strm.cork(); | |
return new BufferStream(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment