@@ -435,7 +435,7 @@ function readableAddChunkUnshiftObjectMode(stream, state, chunk) {
435
435
function readableAddChunkUnshiftValue ( stream , state , chunk ) {
436
436
if ( ( state [ kState ] & kEndEmitted ) !== 0 )
437
437
errorOrDestroy ( stream , new ERR_STREAM_UNSHIFT_AFTER_END_EVENT ( ) ) ;
438
- else if ( state . destroyed || state . errored )
438
+ else if ( ( state [ kState ] & ( kDestroyed | kErrored ) ) !== 0 )
439
439
return false ;
440
440
else
441
441
addChunk ( stream , state , chunk , true ) ;
@@ -604,7 +604,7 @@ function computeNewHighWaterMark(n) {
604
604
// This function is designed to be inlinable, so please take care when making
605
605
// changes to the function body.
606
606
function howMuchToRead ( n , state ) {
607
- if ( n <= 0 || ( state . length === 0 && state . ended ) )
607
+ if ( n <= 0 || ( state . length === 0 && ( state [ kState ] & kEnded ) !== 0 ) )
608
608
return 0 ;
609
609
if ( ( state [ kState ] & kObjectMode ) !== 0 )
610
610
return 1 ;
@@ -648,7 +648,7 @@ Readable.prototype.read = function(n) {
648
648
state . length >= state . highWaterMark :
649
649
state . length > 0 ) ||
650
650
( state [ kState ] & kEnded ) !== 0 ) ) {
651
- debug ( 'read: emitReadable' , state . length , ( state [ kState ] & kEnded ) !== 0 ) ;
651
+ debug ( 'read: emitReadable' ) ;
652
652
if ( state . length === 0 && ( state [ kState ] & kEnded ) !== 0 )
653
653
endReadable ( this ) ;
654
654
else
@@ -806,7 +806,7 @@ function emitReadable(stream) {
806
806
function emitReadable_ ( stream ) {
807
807
const state = stream . _readableState ;
808
808
debug ( 'emitReadable_' ) ;
809
- if ( ( state [ kState ] & ( kDestroyed | kErrored ) ) === 0 && ( state . length || state . ended ) ) {
809
+ if ( ( state [ kState ] & ( kDestroyed | kErrored ) ) === 0 && ( state . length || ( state [ kState ] & kEnded ) !== 0 ) ) {
810
810
stream . emit ( 'readable' ) ;
811
811
state [ kState ] &= ~ kEmittedReadable ;
812
812
}
@@ -887,7 +887,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
887
887
const state = this . _readableState ;
888
888
889
889
if ( state . pipes . length === 1 ) {
890
- if ( ! state . multiAwaitDrain ) {
890
+ if ( ( state [ kState ] & kMultiAwaitDrain ) === 0 ) {
891
891
state [ kState ] |= kMultiAwaitDrain ;
892
892
state . awaitDrainWriters = new SafeSet (
893
893
state . awaitDrainWriters ? [ state . awaitDrainWriters ] : [ ] ,
@@ -903,7 +903,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
903
903
dest !== process . stderr ;
904
904
905
905
const endFn = doEnd ? onend : unpipe ;
906
- if ( state . endEmitted )
906
+ if ( ( state [ kState ] & kEndEmitted ) !== 0 )
907
907
process . nextTick ( endFn ) ;
908
908
else
909
909
src . once ( 'end' , endFn ) ;
@@ -962,7 +962,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
962
962
if ( state . pipes . length === 1 && state . pipes [ 0 ] === dest ) {
963
963
debug ( 'false write response, pause' , 0 ) ;
964
964
state . awaitDrainWriters = dest ;
965
- state . multiAwaitDrain = false ;
965
+ state [ kState ] &= ~ kMultiAwaitDrain ;
966
966
} else if ( state . pipes . length > 1 && state . pipes . includes ( dest ) ) {
967
967
debug ( 'false write response, pause' , state . awaitDrainWriters . size ) ;
968
968
state . awaitDrainWriters . add ( dest ) ;
@@ -1034,7 +1034,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
1034
1034
1035
1035
if ( dest . writableNeedDrain === true ) {
1036
1036
pause ( ) ;
1037
- } else if ( ! state . flowing ) {
1037
+ } else if ( ( state [ kState ] & kFlowing ) === 0 ) {
1038
1038
debug ( 'pipe resume' ) ;
1039
1039
src . resume ( ) ;
1040
1040
}
@@ -1052,7 +1052,7 @@ function pipeOnDrain(src, dest) {
1052
1052
if ( state . awaitDrainWriters === dest ) {
1053
1053
debug ( 'pipeOnDrain' , 1 ) ;
1054
1054
state . awaitDrainWriters = null ;
1055
- } else if ( state . multiAwaitDrain ) {
1055
+ } else if ( ( state [ kState ] & kMultiAwaitDrain ) !== 0 ) {
1056
1056
debug ( 'pipeOnDrain' , state . awaitDrainWriters . size ) ;
1057
1057
state . awaitDrainWriters . delete ( dest ) ;
1058
1058
}
@@ -1107,20 +1107,20 @@ Readable.prototype.on = function(ev, fn) {
1107
1107
if ( ev === 'data' ) {
1108
1108
// Update readableListening so that resume() may be a no-op
1109
1109
// a few lines down. This is needed to support once('readable').
1110
- state . readableListening = this . listenerCount ( 'readable' ) > 0 ;
1110
+ state [ kState ] | = this . listenerCount ( 'readable' ) > 0 ? kReadableListening : 0 ;
1111
1111
1112
1112
// Try start flowing on next tick if stream isn't explicitly paused.
1113
- if ( state . flowing !== false )
1113
+ if ( ( state [ kState ] & ( kHasFlowing | kFlowing ) ) !== kHasFlowing ) {
1114
1114
this . resume ( ) ;
1115
+ }
1115
1116
} else if ( ev === 'readable' ) {
1116
- if ( ! state . endEmitted && ! state . readableListening ) {
1117
- state . readableListening = state . needReadable = true ;
1118
- state . flowing = false ;
1119
- state . emittedReadable = false ;
1120
- debug ( 'on readable' , state . length , state . reading ) ;
1117
+ if ( ( state [ kState ] & ( kEndEmitted | kReadableListening ) ) === 0 ) {
1118
+ state [ kState ] |= kReadableListening | kNeedReadable | kHasFlowing ;
1119
+ state [ kState ] &= ~ ( kFlowing | kEmittedReadable ) ;
1120
+ debug ( 'on readable' ) ;
1121
1121
if ( state . length ) {
1122
1122
emitReadable ( this ) ;
1123
- } else if ( ! state . reading ) {
1123
+ } else if ( ( state [ kState ] & kReading ) === 0 ) {
1124
1124
process . nextTick ( nReadingNextTick , this ) ;
1125
1125
}
1126
1126
}
@@ -1167,7 +1167,12 @@ Readable.prototype.removeAllListeners = function(ev) {
1167
1167
1168
1168
function updateReadableListening ( self ) {
1169
1169
const state = self . _readableState ;
1170
- state . readableListening = self . listenerCount ( 'readable' ) > 0 ;
1170
+
1171
+ if ( self . listenerCount ( 'readable' ) > 0 ) {
1172
+ state [ kState ] |= kReadableListening ;
1173
+ } else {
1174
+ state [ kState ] &= ~ kReadableListening ;
1175
+ }
1171
1176
1172
1177
if ( ( state [ kState ] & ( kHasPaused | kPaused | kResumeScheduled ) ) === ( kHasPaused | kResumeScheduled ) ) {
1173
1178
// Flowing needs to be set to true now, otherwise
@@ -1197,7 +1202,7 @@ Readable.prototype.resume = function() {
1197
1202
// for readable, but we still have to call
1198
1203
// resume().
1199
1204
state [ kState ] |= kHasFlowing ;
1200
- if ( ! state . readableListening ) {
1205
+ if ( ( state [ kState ] & kReadableListening ) === 0 ) {
1201
1206
state [ kState ] |= kFlowing ;
1202
1207
} else {
1203
1208
state [ kState ] &= ~ kFlowing ;
@@ -1210,8 +1215,8 @@ Readable.prototype.resume = function() {
1210
1215
} ;
1211
1216
1212
1217
function resume ( stream , state ) {
1213
- if ( ! state . resumeScheduled ) {
1214
- state . resumeScheduled = true ;
1218
+ if ( ( state [ kState ] & kResumeScheduled ) === 0 ) {
1219
+ state [ kState ] |= kResumeScheduled ;
1215
1220
process . nextTick ( resume_ , stream , state ) ;
1216
1221
}
1217
1222
}
@@ -1232,7 +1237,7 @@ function resume_(stream, state) {
1232
1237
Readable . prototype . pause = function ( ) {
1233
1238
const state = this . _readableState ;
1234
1239
debug ( 'call pause' ) ;
1235
- if ( state . flowing !== false ) {
1240
+ if ( ( state [ kState ] & ( kHasFlowing | kFlowing ) ) !== kHasFlowing ) {
1236
1241
debug ( 'pause' ) ;
1237
1242
state [ kState ] |= kHasFlowing ;
1238
1243
state [ kState ] &= ~ kFlowing ;
@@ -1572,20 +1577,19 @@ function fromList(n, state) {
1572
1577
function endReadable ( stream ) {
1573
1578
const state = stream . _readableState ;
1574
1579
1575
- debug ( 'endReadable' , ( state [ kState ] & kEndEmitted ) !== 0 ) ;
1580
+ debug ( 'endReadable' ) ;
1576
1581
if ( ( state [ kState ] & kEndEmitted ) === 0 ) {
1577
1582
state [ kState ] |= kEnded ;
1578
1583
process . nextTick ( endReadableNT , state , stream ) ;
1579
1584
}
1580
1585
}
1581
1586
1582
1587
function endReadableNT ( state , stream ) {
1583
- debug ( 'endReadableNT' , state . endEmitted , state . length ) ;
1588
+ debug ( 'endReadableNT' ) ;
1584
1589
1585
1590
// Check that we didn't get one last unshift.
1586
- if ( ! state . errored && ! state . closeEmitted &&
1587
- ! state . endEmitted && state . length === 0 ) {
1588
- state . endEmitted = true ;
1591
+ if ( ( state [ kState ] & ( kErrored | kCloseEmitted | kEndEmitted ) ) === 0 && state . length === 0 ) {
1592
+ state [ kState ] |= kEndEmitted ;
1589
1593
stream . emit ( 'end' ) ;
1590
1594
1591
1595
if ( stream . writable && stream . allowHalfOpen === false ) {
0 commit comments