@@ -94,7 +94,7 @@ function ReadableState(options, stream, isDuplex) {
94
94
isDuplex = stream instanceof Stream . Duplex ;
95
95
96
96
// Object stream flag. Used to make read(n) ignore n and to
97
- // make all the buffer merging and length checks go away
97
+ // make all the buffer merging and length checks go away.
98
98
this . objectMode = ! ! ( options && options . objectMode ) ;
99
99
100
100
if ( isDuplex )
@@ -109,7 +109,7 @@ function ReadableState(options, stream, isDuplex) {
109
109
110
110
// A linked list is used to store data chunks instead of an array because the
111
111
// linked list can remove elements from the beginning faster than
112
- // array.shift()
112
+ // array.shift().
113
113
this . buffer = new BufferList ( ) ;
114
114
this . length = 0 ;
115
115
this . pipes = [ ] ;
@@ -132,16 +132,16 @@ function ReadableState(options, stream, isDuplex) {
132
132
this . resumeScheduled = false ;
133
133
this [ kPaused ] = null ;
134
134
135
- // True if the error was already emitted and should not be thrown again
135
+ // True if the error was already emitted and should not be thrown again.
136
136
this . errorEmitted = false ;
137
137
138
138
// Should close be emitted on destroy. Defaults to true.
139
139
this . emitClose = ! options || options . emitClose !== false ;
140
140
141
- // Should .destroy() be called after 'end' (and potentially 'finish')
141
+ // Should .destroy() be called after 'end' (and potentially 'finish').
142
142
this . autoDestroy = ! options || options . autoDestroy !== false ;
143
143
144
- // Has it been destroyed
144
+ // Has it been destroyed.
145
145
this . destroyed = false ;
146
146
147
147
// Indicates whether the stream has errored.
@@ -156,11 +156,11 @@ function ReadableState(options, stream, isDuplex) {
156
156
this . defaultEncoding = ( options && options . defaultEncoding ) || 'utf8' ;
157
157
158
158
// Ref the piped dest which we need a drain event on it
159
- // type: null | Writable | Set<Writable>
159
+ // type: null | Writable | Set<Writable>.
160
160
this . awaitDrainWriters = null ;
161
161
this . multiAwaitDrain = false ;
162
162
163
- // If true, a maybeReadMore has been scheduled
163
+ // If true, a maybeReadMore has been scheduled.
164
164
this . readingMore = false ;
165
165
166
166
this . decoder = null ;
@@ -179,7 +179,7 @@ function Readable(options) {
179
179
return new Readable ( options ) ;
180
180
181
181
// Checking for a Stream.Duplex instance is faster here instead of inside
182
- // the ReadableState constructor, at least with V8 6.5
182
+ // the ReadableState constructor, at least with V8 6.5.
183
183
const isDuplex = this instanceof Stream . Duplex ;
184
184
185
185
this . _readableState = new ReadableState ( options , this , isDuplex ) ;
@@ -213,7 +213,7 @@ Readable.prototype.push = function(chunk, encoding) {
213
213
return readableAddChunk ( this , chunk , encoding , false ) ;
214
214
} ;
215
215
216
- // Unshift should *always* be something directly out of read()
216
+ // Unshift should *always* be something directly out of read().
217
217
Readable . prototype . unshift = function ( chunk , encoding ) {
218
218
return readableAddChunk ( this , chunk , encoding , true ) ;
219
219
} ;
@@ -228,7 +228,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
228
228
encoding = encoding || state . defaultEncoding ;
229
229
if ( addToFront && state . encoding && state . encoding !== encoding ) {
230
230
// When unshifting, if state.encoding is set, we have to save
231
- // the string in the BufferList with the state encoding
231
+ // the string in the BufferList with the state encoding.
232
232
chunk = Buffer . from ( chunk , encoding ) . toString ( state . encoding ) ;
233
233
} else if ( encoding !== state . encoding ) {
234
234
chunk = Buffer . from ( chunk , encoding ) ;
@@ -319,7 +319,7 @@ Readable.prototype.setEncoding = function(enc) {
319
319
StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
320
320
const decoder = new StringDecoder ( enc ) ;
321
321
this . _readableState . decoder = decoder ;
322
- // If setEncoding(null), decoder.encoding equals utf8
322
+ // If setEncoding(null), decoder.encoding equals utf8.
323
323
this . _readableState . encoding = this . _readableState . decoder . encoding ;
324
324
325
325
const buffer = this . _readableState . buffer ;
@@ -335,15 +335,15 @@ Readable.prototype.setEncoding = function(enc) {
335
335
return this ;
336
336
} ;
337
337
338
- // Don't raise the hwm > 1GB
338
+ // Don't raise the hwm > 1GB.
339
339
const MAX_HWM = 0x40000000 ;
340
340
function computeNewHighWaterMark ( n ) {
341
341
if ( n >= MAX_HWM ) {
342
342
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
343
343
n = MAX_HWM ;
344
344
} else {
345
345
// Get the next highest power of 2 to prevent increasing hwm excessively in
346
- // tiny amounts
346
+ // tiny amounts.
347
347
n -- ;
348
348
n |= n >>> 1 ;
349
349
n |= n >>> 2 ;
@@ -363,7 +363,7 @@ function howMuchToRead(n, state) {
363
363
if ( state . objectMode )
364
364
return 1 ;
365
365
if ( NumberIsNaN ( n ) ) {
366
- // Only flow one buffer at a time
366
+ // Only flow one buffer at a time.
367
367
if ( state . flowing && state . length )
368
368
return state . buffer . first ( ) . length ;
369
369
else
@@ -446,7 +446,7 @@ Readable.prototype.read = function(n) {
446
446
let doRead = state . needReadable ;
447
447
debug ( 'need readable' , doRead ) ;
448
448
449
- // If we currently have less than the highWaterMark, then also read some
449
+ // If we currently have less than the highWaterMark, then also read some.
450
450
if ( state . length === 0 || state . length - n < state . highWaterMark ) {
451
451
doRead = true ;
452
452
debug ( 'length less than watermark' , doRead ) ;
@@ -524,7 +524,7 @@ function onEofChunk(stream, state) {
524
524
if ( state . sync ) {
525
525
// If we are sync, wait until next tick to emit the data.
526
526
// Otherwise we risk emitting data in the flow()
527
- // the readable code triggers during a read() call
527
+ // the readable code triggers during a read() call.
528
528
emitReadable ( stream ) ;
529
529
} else {
530
530
// Emit 'readable' now to make sure it gets picked up.
@@ -558,7 +558,7 @@ function emitReadable_(stream) {
558
558
state . emittedReadable = false ;
559
559
}
560
560
561
- // The stream needs another readable event if
561
+ // The stream needs another readable event if:
562
562
// 1. It is not flowing, as the flow mechanism will take
563
563
// care of it.
564
564
// 2. It is not ended.
@@ -677,7 +677,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
677
677
let cleanedUp = false ;
678
678
function cleanup ( ) {
679
679
debug ( 'cleanup' ) ;
680
- // Cleanup event handlers once the pipe is broken
680
+ // Cleanup event handlers once the pipe is broken.
681
681
dest . removeListener ( 'close' , onclose ) ;
682
682
dest . removeListener ( 'finish' , onfinish ) ;
683
683
if ( ondrain ) {
@@ -771,7 +771,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
771
771
src . unpipe ( dest ) ;
772
772
}
773
773
774
- // Tell the dest that it's being piped to
774
+ // Tell the dest that it's being piped to.
775
775
dest . emit ( 'pipe' , src ) ;
776
776
777
777
// Start the flow if it hasn't been started already.
@@ -841,7 +841,7 @@ Readable.prototype.unpipe = function(dest) {
841
841
} ;
842
842
843
843
// Set up data events if they are asked for
844
- // Ensure readable listeners eventually get something
844
+ // Ensure readable listeners eventually get something.
845
845
Readable . prototype . on = function ( ev , fn ) {
846
846
const res = Stream . prototype . on . call ( this , ev , fn ) ;
847
847
const state = this . _readableState ;
@@ -851,7 +851,7 @@ Readable.prototype.on = function(ev, fn) {
851
851
// a few lines down. This is needed to support once('readable').
852
852
state . readableListening = this . listenerCount ( 'readable' ) > 0 ;
853
853
854
- // Try start flowing on next tick if stream isn't explicitly paused
854
+ // Try start flowing on next tick if stream isn't explicitly paused.
855
855
if ( state . flowing !== false )
856
856
this . resume ( ) ;
857
857
} else if ( ev === 'readable' ) {
@@ -914,7 +914,7 @@ function updateReadableListening(self) {
914
914
// the upcoming resume will not flow.
915
915
state . flowing = true ;
916
916
917
- // Crude way to check if we should resume
917
+ // Crude way to check if we should resume.
918
918
} else if ( self . listenerCount ( 'data' ) > 0 ) {
919
919
self . resume ( ) ;
920
920
} else if ( ! state . readableListening ) {
@@ -935,7 +935,7 @@ Readable.prototype.resume = function() {
935
935
debug ( 'resume' ) ;
936
936
// We flow only if there is no one listening
937
937
// for readable, but we still have to call
938
- // resume()
938
+ // resume().
939
939
state . flowing = ! state . readableListening ;
940
940
resume ( this , state ) ;
941
941
}
@@ -1003,7 +1003,7 @@ Readable.prototype.wrap = function(stream) {
1003
1003
if ( state . decoder )
1004
1004
chunk = state . decoder . write ( chunk ) ;
1005
1005
1006
- // Don't skip over falsy values in objectMode
1006
+ // Don't skip over falsy values in objectMode.
1007
1007
if ( state . objectMode && ( chunk === null || chunk === undefined ) )
1008
1008
return ;
1009
1009
else if ( ! state . objectMode && ( ! chunk || ! chunk . length ) )
@@ -1055,7 +1055,7 @@ Readable.prototype[SymbolAsyncIterator] = function() {
1055
1055
1056
1056
// Making it explicit these properties are not enumerable
1057
1057
// because otherwise some prototype manipulation in
1058
- // userland will fail
1058
+ // userland will fail.
1059
1059
ObjectDefineProperties ( Readable . prototype , {
1060
1060
readable : {
1061
1061
get ( ) {
@@ -1132,13 +1132,13 @@ ObjectDefineProperties(Readable.prototype, {
1132
1132
} ,
1133
1133
set ( value ) {
1134
1134
// We ignore the value if the stream
1135
- // has not been initialized yet
1135
+ // has not been initialized yet.
1136
1136
if ( ! this . _readableState ) {
1137
1137
return ;
1138
1138
}
1139
1139
1140
1140
// Backward compatibility, the user is explicitly
1141
- // managing destroyed
1141
+ // managing destroyed.
1142
1142
this . _readableState . destroyed = value ;
1143
1143
}
1144
1144
} ,
@@ -1175,15 +1175,15 @@ Readable._fromList = fromList;
1175
1175
// This function is designed to be inlinable, so please take care when making
1176
1176
// changes to the function body.
1177
1177
function fromList ( n , state ) {
1178
- // nothing buffered
1178
+ // nothing buffered.
1179
1179
if ( state . length === 0 )
1180
1180
return null ;
1181
1181
1182
1182
let ret ;
1183
1183
if ( state . objectMode )
1184
1184
ret = state . buffer . shift ( ) ;
1185
1185
else if ( ! n || n >= state . length ) {
1186
- // Read it all, truncate the list
1186
+ // Read it all, truncate the list.
1187
1187
if ( state . decoder )
1188
1188
ret = state . buffer . join ( '' ) ;
1189
1189
else if ( state . buffer . length === 1 )
@@ -1192,7 +1192,7 @@ function fromList(n, state) {
1192
1192
ret = state . buffer . concat ( state . length ) ;
1193
1193
state . buffer . clear ( ) ;
1194
1194
} else {
1195
- // read part of list
1195
+ // read part of list.
1196
1196
ret = state . buffer . consume ( n , state . decoder ) ;
1197
1197
}
1198
1198
@@ -1221,7 +1221,7 @@ function endReadableNT(state, stream) {
1221
1221
process . nextTick ( endWritableNT , state , stream ) ;
1222
1222
} else if ( state . autoDestroy ) {
1223
1223
// In case of duplex streams we need a way to detect
1224
- // if the writable side is ready for autoDestroy as well
1224
+ // if the writable side is ready for autoDestroy as well.
1225
1225
const wState = stream . _writableState ;
1226
1226
const autoDestroy = ! wState || (
1227
1227
wState . autoDestroy &&
0 commit comments