Skip to content

Commit

Permalink
fixup! stream: consolidate common code from readable push and unshift…
Browse files Browse the repository at this point in the history
… helper functions
  • Loading branch information
wa-Nadoo committed Oct 26, 2023
1 parent a3cb8ba commit b5e9176
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,18 @@ Readable.prototype.push = function(chunk, encoding) {
debug('push', chunk);

const state = this._readableState;
if ((state[kState] & kEnded) !== 0) {
errorOrDestroy(this, new ERR_STREAM_PUSH_AFTER_EOF());
return false;
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
return false;

state[kState] &= ~kReading;
if (chunk === null) {
onEofChunk(this, state);
return false;
}

if ((state[kState] & kEnded) !== 0) {
errorOrDestroy(this, new ERR_STREAM_PUSH_AFTER_EOF());
return false;
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
return false;

return (state[kState] & kObjectMode) === 0 ?
readableAddChunkPushByteMode(this, state, chunk, encoding) :
readableAddChunkPushObjectMode(this, state, chunk, encoding);
Expand All @@ -388,18 +388,18 @@ Readable.prototype.push = function(chunk, encoding) {
Readable.prototype.unshift = function(chunk, encoding) {
debug('unshift', chunk);
const state = this._readableState;
if ((state[kState] & kEndEmitted) !== 0) {
errorOrDestroy(this, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
return false;
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
return false;

if (chunk === null) {
state[kState] &= ~kReading;
onEofChunk(this, state);
return false;
}

if ((state[kState] & kEndEmitted) !== 0) {
errorOrDestroy(this, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());
return false;
} else if ((state[kState] & (kDestroyed | kErrored)) !== 0)
return false;

return (state[kState] & kObjectMode) === 0 ?
readableAddChunkUnshiftByteMode(this, state, chunk, encoding) :
readableAddChunkUnshiftObjectMode(this, state, chunk);
Expand Down

0 comments on commit b5e9176

Please sign in to comment.