Skip to content

Commit

Permalink
stream: simplify howMuchToRead
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 16, 2019
1 parent a15cd9d commit df1756e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,9 @@ function howMuchToRead(n, state) {
else
return state.length;
}
// If we're asking for more than the current hwm, then raise the hwm.
if (n > state.highWaterMark)
state.highWaterMark = computeNewHighWaterMark(n);
if (n <= state.length)
return n;
// Don't have enough
if (!state.ended) {
state.needReadable = true;
return 0;
}
return state.length;
return state.ended ? state.length : 0;
}

// You can override either this method, or the async _read(n) below.
Expand All @@ -409,6 +401,10 @@ Readable.prototype.read = function(n) {
const state = this._readableState;
const nOrig = n;

// If we're asking for more than the current hwm, then raise the hwm.
if (n > state.highWaterMark)
state.highWaterMark = computeNewHighWaterMark(n);

if (n !== 0)
state.emittedReadable = false;

Expand Down

0 comments on commit df1756e

Please sign in to comment.