Skip to content

Commit df1756e

Browse files
committed
stream: simplify howMuchToRead
1 parent a15cd9d commit df1756e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/_stream_readable.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,9 @@ function howMuchToRead(n, state) {
383383
else
384384
return state.length;
385385
}
386-
// If we're asking for more than the current hwm, then raise the hwm.
387-
if (n > state.highWaterMark)
388-
state.highWaterMark = computeNewHighWaterMark(n);
389386
if (n <= state.length)
390387
return n;
391-
// Don't have enough
392-
if (!state.ended) {
393-
state.needReadable = true;
394-
return 0;
395-
}
396-
return state.length;
388+
return state.ended ? state.length : 0;
397389
}
398390

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

404+
// If we're asking for more than the current hwm, then raise the hwm.
405+
if (n > state.highWaterMark)
406+
state.highWaterMark = computeNewHighWaterMark(n);
407+
412408
if (n !== 0)
413409
state.emittedReadable = false;
414410

0 commit comments

Comments
 (0)