Skip to content

Commit 30ad6c0

Browse files
committed
fixup
1 parent d6f1c7d commit 30ad6c0

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/internal/streams/readable.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
378378
if ((state.state & kObjectMode) === 0) {
379379
if (typeof chunk === 'string') {
380380
encoding = encoding || ((state.state & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state[kDefaultEncodingValue]);
381-
if ((state.state | kEncoding) === 0 || state.encoding !== encoding) {
382-
if (addToFront && state.encoding) {
381+
if ((state.state & kEncoding) === 0 || state.encoding !== encoding) {
382+
if (addToFront && (state.state & kEncoding) !== 0) {
383383
// When unshifting, if state.encoding is set, we have to save
384384
// the string in the BufferList with the state encoding.
385-
chunk = Buffer.from(chunk, encoding).toString(state.encoding);
385+
chunk = Buffer.from(chunk, encoding).toString(state[kEncodingValue]);
386386
} else {
387387
chunk = Buffer.from(chunk, encoding);
388388
encoding = '';
@@ -412,7 +412,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
412412
return false;
413413
else
414414
addChunk(stream, state, chunk, true);
415-
} else if (state.ended) {
415+
} else if ((state.state & kEnded) !== 0) {
416416
errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
417417
} else if ((state.state & (kDestroyed | kErrored)) !== 0) {
418418
return false;
@@ -436,7 +436,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
436436
// We can push more data if we are below the highWaterMark.
437437
// Also, if we have no data yet, we can stand some more bytes.
438438
// This is to work around cases where hwm=0, such as the repl.
439-
return !state.ended &&
439+
return (state.state & kEnded) === 0 &&
440440
(state.length < state.highWaterMark || state.length === 0);
441441
}
442442

@@ -529,7 +529,7 @@ function howMuchToRead(n, state) {
529529
}
530530
if (n <= state.length)
531531
return n;
532-
return state.ended ? state.length : 0;
532+
return (state.state & kEnded) !== 0 ? state.length : 0;
533533
}
534534

535535
// You can override either this method, or the async _read(n) below.
@@ -561,8 +561,7 @@ Readable.prototype.read = function(n) {
561561
state.length >= state.highWaterMark :
562562
state.length > 0) ||
563563
(state.state & kEnded) !== 0)) {
564-
debug('read: emitReadable', state.length, state.ended);
565-
if (state.length === 0 && state.ended)
564+
if (state.length === 0 && (state.state & kEnded) !== 0)
566565
endReadable(this);
567566
else
568567
emitReadable(this);
@@ -656,7 +655,7 @@ Readable.prototype.read = function(n) {
656655
n = 0;
657656
} else {
658657
state.length -= n;
659-
if (state.multiAwaitDrain) {
658+
if ((state.state & kMultiAwaitDrain) !== 0) {
660659
state.awaitDrainWriters.clear();
661660
} else {
662661
state.awaitDrainWriters = null;
@@ -686,7 +685,7 @@ Readable.prototype.read = function(n) {
686685

687686
function onEofChunk(stream, state) {
688687
debug('onEofChunk');
689-
if (state.ended) return;
688+
if ((state.state & kEnded) !== 0) return;
690689
if ((state.state & kDecoder) !== 0) {
691690
const chunk = state[kDecoderValue].end();
692691
if (chunk && chunk.length) {
@@ -810,8 +809,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
810809
const state = this._readableState;
811810

812811
if (state.pipes.length === 1) {
813-
if (!state.multiAwaitDrain) {
814-
state.multiAwaitDrain = true;
812+
if ((state.state & kMultiAwaitDrain) === 0) {
813+
state.state |= kMultiAwaitDrain;
815814
state.awaitDrainWriters = new SafeSet(
816815
state.awaitDrainWriters ? [state.awaitDrainWriters] : [],
817816
);
@@ -826,7 +825,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
826825
dest !== process.stderr;
827826

828827
const endFn = doEnd ? onend : unpipe;
829-
if (state.endEmitted)
828+
if ((state.state & kEndEmitted) !== 0)
830829
process.nextTick(endFn);
831830
else
832831
src.once('end', endFn);
@@ -885,7 +884,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
885884
if (state.pipes.length === 1 && state.pipes[0] === dest) {
886885
debug('false write response, pause', 0);
887886
state.awaitDrainWriters = dest;
888-
state.multiAwaitDrain = false;
887+
state.state &= ~kMultiAwaitDrain;
889888
} else if (state.pipes.length > 1 && state.pipes.includes(dest)) {
890889
debug('false write response, pause', state.awaitDrainWriters.size);
891890
state.awaitDrainWriters.add(dest);
@@ -975,7 +974,7 @@ function pipeOnDrain(src, dest) {
975974
if (state.awaitDrainWriters === dest) {
976975
debug('pipeOnDrain', 1);
977976
state.awaitDrainWriters = null;
978-
} else if (state.multiAwaitDrain) {
977+
} else if ((state.state & kMultiAwaitDrain) !== 0) {
979978
debug('pipeOnDrain', state.awaitDrainWriters.size);
980979
state.awaitDrainWriters.delete(dest);
981980
}
@@ -1043,10 +1042,10 @@ Readable.prototype.on = function(ev, fn) {
10431042
state.state |= (kHasFlowing | kNeedReadable | kReadableListening);
10441043
state.state &= ~(kFlowing | kEmittedReadable);
10451044

1046-
debug('on readable', state.length, state.reading);
1045+
debug('on readable', state.length, (state.state & kReading) !== 0);
10471046
if (state.length) {
10481047
emitReadable(this);
1049-
} else if (!state.reading) {
1048+
} else if ((state.state & kReading) === 0) {
10501049
process.nextTick(nReadingNextTick, this);
10511050
}
10521051
}
@@ -1123,7 +1122,7 @@ Readable.prototype.resume = function() {
11231122
// for readable, but we still have to call
11241123
// resume().
11251124
state.state |= kHasFlowing;
1126-
if (!state.readableListening) {
1125+
if ((state.state & kReadableListening) === 0) {
11271126
state.state |= kFlowing;
11281127
} else {
11291128
state.state &= ~kFlowing;

0 commit comments

Comments
 (0)