diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index fecd34fa791722..b1454ac4321be6 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -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); @@ -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);