diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 825042baa57..333a3a015d8 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -137,8 +137,13 @@ function howMuchToRead(n, state) { if (state.objectMode) return n === 0 ? 0 : 1; - if (isNaN(n) || n === null) - return state.length; + if (isNaN(n) || n === null) { + // only flow one buffer at a time + if (state.flowing && state.buffer.length) + return state.buffer[0].length; + else + return state.length; + } if (n <= 0) return 0;