Skip to content

Instantly share code, notes, and snippets.

@isaacs isaacs/gist:4688017
Created Feb 1, 2013

Embed
What would you like to do?
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 630a3f3..de7d4e3 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -107,7 +107,18 @@ function Readable(options) {
// write() some more.
Readable.prototype.push = function(chunk) {
var rs = this._readableState;
- rs.onread(null, chunk);
+
+ if (rs.flowing && rs.length === 0 &&
+ chunk !== null && chunk !== undefined &&
+ (rs.objectMode || chunk.length)) {
+ // console.error('R pushPipe optimization');
+ pipeWrite(this, rs, chunk);
+ if (rs.awaitDrain <= 0) {
+ pipeAfterWrite(this, rs);
+ }
+ } else {
+ rs.onread(null, chunk);
+ }
// if it's past the high water mark, we can push in some more.
// Also, if it's still within the lowWaterMark, we can stand some
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.