Skip to content

Commit b5e9176

Browse files
committed
fixup! stream: consolidate common code from readable push and unshift helper functions
1 parent a3cb8ba commit b5e9176

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

lib/internal/streams/readable.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,18 @@ Readable.prototype.push = function(chunk, encoding) {
367367
debug('push', chunk);
368368

369369
const state = this._readableState;
370-
if ((state[kState] & kEnded) !== 0) {
371-
errorOrDestroy(this, new ERR_STREAM_PUSH_AFTER_EOF());
372-
return false;
373-
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
374-
return false;
375-
376370
state[kState] &= ~kReading;
377371
if (chunk === null) {
378372
onEofChunk(this, state);
379373
return false;
380374
}
381375

376+
if ((state[kState] & kEnded) !== 0) {
377+
errorOrDestroy(this, new ERR_STREAM_PUSH_AFTER_EOF());
378+
return false;
379+
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
380+
return false;
381+
382382
return (state[kState] & kObjectMode) === 0 ?
383383
readableAddChunkPushByteMode(this, state, chunk, encoding) :
384384
readableAddChunkPushObjectMode(this, state, chunk, encoding);
@@ -388,18 +388,18 @@ Readable.prototype.push = function(chunk, encoding) {
388388
Readable.prototype.unshift = function(chunk, encoding) {
389389
debug('unshift', chunk);
390390
const state = this._readableState;
391-
if ((state[kState] & kEndEmitted) !== 0) {
392-
errorOrDestroy(this, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
393-
return false;
394-
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
395-
return false;
396-
397391
if (chunk === null) {
398392
state[kState] &= ~kReading;
399393
onEofChunk(this, state);
400394
return false;
401395
}
402396

397+
if ((state[kState] & kEndEmitted) !== 0) {
398+
errorOrDestroy(this, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
399+
return false;
400+
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
401+
return false;
402+
403403
return (state[kState] & kObjectMode) === 0 ?
404404
readableAddChunkUnshiftByteMode(this, state, chunk, encoding) :
405405
readableAddChunkUnshiftObjectMode(this, state, chunk);

0 commit comments

Comments
 (0)