@@ -378,11 +378,11 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
378
378
if ( ( state . state & kObjectMode ) === 0 ) {
379
379
if ( typeof chunk === 'string' ) {
380
380
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 ) {
383
383
// When unshifting, if state.encoding is set, we have to save
384
384
// 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 ] ) ;
386
386
} else {
387
387
chunk = Buffer . from ( chunk , encoding ) ;
388
388
encoding = '' ;
@@ -412,7 +412,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
412
412
return false ;
413
413
else
414
414
addChunk ( stream , state , chunk , true ) ;
415
- } else if ( state . ended ) {
415
+ } else if ( ( state . state & kEnded ) !== 0 ) {
416
416
errorOrDestroy ( stream , new ERR_STREAM_PUSH_AFTER_EOF ( ) ) ;
417
417
} else if ( ( state . state & ( kDestroyed | kErrored ) ) !== 0 ) {
418
418
return false ;
@@ -436,7 +436,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
436
436
// We can push more data if we are below the highWaterMark.
437
437
// Also, if we have no data yet, we can stand some more bytes.
438
438
// This is to work around cases where hwm=0, such as the repl.
439
- return ! state . ended &&
439
+ return ( state . state & kEnded ) === 0 &&
440
440
( state . length < state . highWaterMark || state . length === 0 ) ;
441
441
}
442
442
@@ -529,7 +529,7 @@ function howMuchToRead(n, state) {
529
529
}
530
530
if ( n <= state . length )
531
531
return n ;
532
- return state . ended ? state . length : 0 ;
532
+ return ( state . state & kEnded ) !== 0 ? state . length : 0 ;
533
533
}
534
534
535
535
// You can override either this method, or the async _read(n) below.
@@ -561,8 +561,7 @@ Readable.prototype.read = function(n) {
561
561
state . length >= state . highWaterMark :
562
562
state . length > 0 ) ||
563
563
( 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 )
566
565
endReadable ( this ) ;
567
566
else
568
567
emitReadable ( this ) ;
@@ -656,7 +655,7 @@ Readable.prototype.read = function(n) {
656
655
n = 0 ;
657
656
} else {
658
657
state . length -= n ;
659
- if ( state . multiAwaitDrain ) {
658
+ if ( ( state . state & kMultiAwaitDrain ) !== 0 ) {
660
659
state . awaitDrainWriters . clear ( ) ;
661
660
} else {
662
661
state . awaitDrainWriters = null ;
@@ -686,7 +685,7 @@ Readable.prototype.read = function(n) {
686
685
687
686
function onEofChunk ( stream , state ) {
688
687
debug ( 'onEofChunk' ) ;
689
- if ( state . ended ) return ;
688
+ if ( ( state . state & kEnded ) !== 0 ) return ;
690
689
if ( ( state . state & kDecoder ) !== 0 ) {
691
690
const chunk = state [ kDecoderValue ] . end ( ) ;
692
691
if ( chunk && chunk . length ) {
@@ -810,8 +809,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
810
809
const state = this . _readableState ;
811
810
812
811
if ( state . pipes . length === 1 ) {
813
- if ( ! state . multiAwaitDrain ) {
814
- state . multiAwaitDrain = true ;
812
+ if ( ( state . state & kMultiAwaitDrain ) === 0 ) {
813
+ state . state |= kMultiAwaitDrain ;
815
814
state . awaitDrainWriters = new SafeSet (
816
815
state . awaitDrainWriters ? [ state . awaitDrainWriters ] : [ ] ,
817
816
) ;
@@ -826,7 +825,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
826
825
dest !== process . stderr ;
827
826
828
827
const endFn = doEnd ? onend : unpipe ;
829
- if ( state . endEmitted )
828
+ if ( ( state . state & kEndEmitted ) !== 0 )
830
829
process . nextTick ( endFn ) ;
831
830
else
832
831
src . once ( 'end' , endFn ) ;
@@ -885,7 +884,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
885
884
if ( state . pipes . length === 1 && state . pipes [ 0 ] === dest ) {
886
885
debug ( 'false write response, pause' , 0 ) ;
887
886
state . awaitDrainWriters = dest ;
888
- state . multiAwaitDrain = false ;
887
+ state . state &= ~ kMultiAwaitDrain ;
889
888
} else if ( state . pipes . length > 1 && state . pipes . includes ( dest ) ) {
890
889
debug ( 'false write response, pause' , state . awaitDrainWriters . size ) ;
891
890
state . awaitDrainWriters . add ( dest ) ;
@@ -975,7 +974,7 @@ function pipeOnDrain(src, dest) {
975
974
if ( state . awaitDrainWriters === dest ) {
976
975
debug ( 'pipeOnDrain' , 1 ) ;
977
976
state . awaitDrainWriters = null ;
978
- } else if ( state . multiAwaitDrain ) {
977
+ } else if ( ( state . state & kMultiAwaitDrain ) !== 0 ) {
979
978
debug ( 'pipeOnDrain' , state . awaitDrainWriters . size ) ;
980
979
state . awaitDrainWriters . delete ( dest ) ;
981
980
}
@@ -1043,10 +1042,10 @@ Readable.prototype.on = function(ev, fn) {
1043
1042
state . state |= ( kHasFlowing | kNeedReadable | kReadableListening ) ;
1044
1043
state . state &= ~ ( kFlowing | kEmittedReadable ) ;
1045
1044
1046
- debug ( 'on readable' , state . length , state . reading ) ;
1045
+ debug ( 'on readable' , state . length , ( state . state & kReading ) !== 0 ) ;
1047
1046
if ( state . length ) {
1048
1047
emitReadable ( this ) ;
1049
- } else if ( ! state . reading ) {
1048
+ } else if ( ( state . state & kReading ) === 0 ) {
1050
1049
process . nextTick ( nReadingNextTick , this ) ;
1051
1050
}
1052
1051
}
@@ -1123,7 +1122,7 @@ Readable.prototype.resume = function() {
1123
1122
// for readable, but we still have to call
1124
1123
// resume().
1125
1124
state . state |= kHasFlowing ;
1126
- if ( ! state . readableListening ) {
1125
+ if ( ( state . state & kReadableListening ) === 0 ) {
1127
1126
state . state |= kFlowing ;
1128
1127
} else {
1129
1128
state . state &= ~ kFlowing ;
0 commit comments