Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 1, 2013 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4688017 to your computer and use it in GitHub Desktop.
Save isaacs/4688017 to your computer and use it in GitHub Desktop.
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