@@ -183,7 +183,6 @@ function ReadableState(options, stream, isDuplex) {
183
183
this . state |= kObjectMode ;
184
184
stream . push = readableAddChunkPushObjectMode ;
185
185
stream . unshift = readableAddChunkUnshiftObjectMode ;
186
-
187
186
} else {
188
187
this . state &= ~ kObjectMode ;
189
188
stream . push = readableAddChunkPushByteMode ;
@@ -290,14 +289,16 @@ function Readable(options) {
290
289
}
291
290
} ) ;
292
291
292
+ const isObjectMode = this . _readableState . objectMode ;
293
+
293
294
// Manually shove something into the read() buffer.
294
295
// This returns true if the highWaterMark has not been hit yet,
295
296
// similar to how Writable.write() returns true if you should
296
297
// write() some more.
297
- this . push = this . _readableState . objectMode ? readableAddChunkPushObjectMode : readableAddChunkPushByteMode ;
298
+ this . push = isObjectMode ? readableAddChunkPushObjectMode : readableAddChunkPushByteMode ;
298
299
299
300
// Unshift should *always* be something directly out of read().
300
- this . unshift = this . _readableState . objectMode ? readableAddChunkUnshiftObjectMode : readableAddChunkUnshiftByteMode ;
301
+ this . unshift = isObjectMode ? readableAddChunkUnshiftObjectMode : readableAddChunkUnshiftByteMode ;
301
302
}
302
303
303
304
Readable . prototype . destroy = destroyImpl . destroy ;
@@ -478,12 +479,12 @@ function canPushMore(state) {
478
479
// Also, if we have no data yet, we can stand some more bytes.
479
480
// This is to work around cases where hwm=0, such as the repl.
480
481
return ! state . ended &&
481
- ( state . length < state . highWaterMark || state . length === 0 ) ;
482
+ ( state . length < state . highWaterMark || state . length === 0 ) ;
482
483
}
483
484
484
485
function addChunk ( stream , state , chunk , addToFront ) {
485
486
if ( state . flowing && state . length === 0 && ! state . sync &&
486
- stream . listenerCount ( 'data' ) > 0 ) {
487
+ stream . listenerCount ( 'data' ) > 0 ) {
487
488
// Use the guard to avoid creating `Set()` repeatedly
488
489
// when we have multiple pipes.
489
490
if ( ( state . state & kMultiAwaitDrain ) !== 0 ) {
@@ -594,11 +595,11 @@ Readable.prototype.read = function(n) {
594
595
// already have a bunch of data in the buffer, then just trigger
595
596
// the 'readable' event and move on.
596
597
if ( n === 0 &&
597
- state . needReadable &&
598
- ( ( state . highWaterMark !== 0 ?
599
- state . length >= state . highWaterMark :
600
- state . length > 0 ) ||
601
- state . ended ) ) {
598
+ state . needReadable &&
599
+ ( ( state . highWaterMark !== 0 ?
600
+ state . length >= state . highWaterMark :
601
+ state . length > 0 ) ||
602
+ state . ended ) ) {
602
603
debug ( 'read: emitReadable' , state . length , state . ended ) ;
603
604
if ( state . length === 0 && state . ended )
604
605
endReadable ( this ) ;
@@ -652,7 +653,7 @@ Readable.prototype.read = function(n) {
652
653
// reading, then it's unnecessary, if we're constructing we have to wait,
653
654
// and if we're destroyed or errored, then it's not allowed,
654
655
if ( state . ended || state . reading || state . destroyed || state . errored ||
655
- ! state . constructed ) {
656
+ ! state . constructed ) {
656
657
doRead = false ;
657
658
debug ( 'reading, ended or constructing' , doRead ) ;
658
659
} else if ( doRead ) {
@@ -769,9 +770,9 @@ function emitReadable_(stream) {
769
770
// 3. It is below the highWaterMark, so we can schedule
770
771
// another readable later.
771
772
state . needReadable =
772
- ! state . flowing &&
773
- ! state . ended &&
774
- state . length <= state . highWaterMark ;
773
+ ! state . flowing &&
774
+ ! state . ended &&
775
+ state . length <= state . highWaterMark ;
775
776
flow ( stream ) ;
776
777
}
777
778
@@ -814,13 +815,13 @@ function maybeReadMore_(stream, state) {
814
815
// read()s. The execution ends in this method again after the _read() ends
815
816
// up calling push() with more data.
816
817
while ( ! state . reading && ! state . ended &&
817
- ( state . length < state . highWaterMark ||
818
- ( state . flowing && state . length === 0 ) ) ) {
818
+ ( state . length < state . highWaterMark ||
819
+ ( state . flowing && state . length === 0 ) ) ) {
819
820
const len = state . length ;
820
821
debug ( 'maybeReadMore read 0' ) ;
821
822
stream . read ( 0 ) ;
822
823
if ( len === state . length )
823
- // Didn't get any data, stop spinning.
824
+ // Didn't get any data, stop spinning.
824
825
break ;
825
826
}
826
827
state . readingMore = false ;
@@ -851,8 +852,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
851
852
debug ( 'pipe count=%d opts=%j' , state . pipes . length , pipeOpts ) ;
852
853
853
854
const doEnd = ( ! pipeOpts || pipeOpts . end !== false ) &&
854
- dest !== process . stdout &&
855
- dest !== process . stderr ;
855
+ dest !== process . stdout &&
856
+ dest !== process . stderr ;
856
857
857
858
const endFn = doEnd ? onend : unpipe ;
858
859
if ( state . endEmitted )
@@ -901,7 +902,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
901
902
// So, if this is awaiting a drain, then we just call it now.
902
903
// If we don't know, then assume that we are waiting for one.
903
904
if ( ondrain && state . awaitDrainWriters &&
904
- ( ! dest . _writableState || dest . _writableState . needDrain ) )
905
+ ( ! dest . _writableState || dest . _writableState . needDrain ) )
905
906
ondrain ( ) ;
906
907
}
907
908
@@ -1010,7 +1011,7 @@ function pipeOnDrain(src, dest) {
1010
1011
}
1011
1012
1012
1013
if ( ( ! state . awaitDrainWriters || state . awaitDrainWriters . size === 0 ) &&
1013
- src . listenerCount ( 'data' ) ) {
1014
+ src . listenerCount ( 'data' ) ) {
1014
1015
src . resume ( ) ;
1015
1016
}
1016
1017
} ;
@@ -1305,7 +1306,7 @@ async function* createAsyncIterator(stream, options) {
1305
1306
} finally {
1306
1307
if (
1307
1308
( error || options ?. destroyOnReturn !== false ) &&
1308
- ( error === undefined || stream . _readableState . autoDestroy )
1309
+ ( error === undefined || stream . _readableState . autoDestroy )
1309
1310
) {
1310
1311
destroyImpl . destroyer ( stream , null ) ;
1311
1312
} else {
@@ -1328,7 +1329,7 @@ ObjectDefineProperties(Readable.prototype, {
1328
1329
// Compat. The user might manually disable readable side through
1329
1330
// deprecated setter.
1330
1331
return ! ! r && r . readable !== false && ! r . destroyed && ! r . errorEmitted &&
1331
- ! r . endEmitted ;
1332
+ ! r . endEmitted ;
1332
1333
} ,
1333
1334
set ( val ) {
1334
1335
// Backwards compat.
@@ -1352,8 +1353,8 @@ ObjectDefineProperties(Readable.prototype, {
1352
1353
get : function ( ) {
1353
1354
return ! ! (
1354
1355
this . _readableState . readable !== false &&
1355
- ( this . _readableState . destroyed || this . _readableState . errored ) &&
1356
- ! this . _readableState . endEmitted
1356
+ ( this . _readableState . destroyed || this . _readableState . errored ) &&
1357
+ ! this . _readableState . endEmitted
1357
1358
) ;
1358
1359
} ,
1359
1360
} ,
@@ -1523,7 +1524,7 @@ function endReadableNT(state, stream) {
1523
1524
1524
1525
// Check that we didn't get one last unshift.
1525
1526
if ( ! state . errored && ! state . closeEmitted &&
1526
- ! state . endEmitted && state . length === 0 ) {
1527
+ ! state . endEmitted && state . length === 0 ) {
1527
1528
state . endEmitted = true ;
1528
1529
stream . emit ( 'end' ) ;
1529
1530
@@ -1535,9 +1536,9 @@ function endReadableNT(state, stream) {
1535
1536
const wState = stream . _writableState ;
1536
1537
const autoDestroy = ! wState || (
1537
1538
wState . autoDestroy &&
1538
- // We don't expect the writable to ever 'finish'
1539
- // if writable is explicitly set to false.
1540
- ( wState . finished || wState . writable === false )
1539
+ // We don't expect the writable to ever 'finish'
1540
+ // if writable is explicitly set to false.
1541
+ ( wState . finished || wState . writable === false )
1541
1542
) ;
1542
1543
1543
1544
if ( autoDestroy ) {
@@ -1549,7 +1550,7 @@ function endReadableNT(state, stream) {
1549
1550
1550
1551
function endWritableNT ( stream ) {
1551
1552
const writable = stream . writable && ! stream . writableEnded &&
1552
- ! stream . destroyed ;
1553
+ ! stream . destroyed ;
1553
1554
if ( writable ) {
1554
1555
stream . end ( ) ;
1555
1556
}
0 commit comments