diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 416706363ad..825042baa57 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -163,6 +163,16 @@ Readable.prototype.read = function(n) { if (typeof n !== 'number' || n > 0) state.emittedReadable = false; + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && + state.needReadable && + state.length >= state.highWaterMark) { + emitReadable(this); + return null; + } + n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.