@@ -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. When true no further
@@ -159,11 +159,11 @@ function ReadableState(options, stream, isDuplex) {
159
159
this . defaultEncoding = ( options && options . defaultEncoding ) || 'utf8' ;
160
160
161
161
// Ref the piped dest which we need a drain event on it
162
- // type: null | Writable | Set<Writable>
162
+ // type: null | Writable | Set<Writable>.
163
163
this . awaitDrainWriters = null ;
164
164
this . multiAwaitDrain = false ;
165
165
166
- // If true, a maybeReadMore has been scheduled
166
+ // If true, a maybeReadMore has been scheduled.
167
167
this . readingMore = false ;
168
168
169
169
this . decoder = null ;
@@ -182,7 +182,7 @@ function Readable(options) {
182
182
return new Readable ( options ) ;
183
183
184
184
// Checking for a Stream.Duplex instance is faster here instead of inside
185
- // the ReadableState constructor, at least with V8 6.5
185
+ // the ReadableState constructor, at least with V8 6.5.
186
186
const isDuplex = this instanceof Stream . Duplex ;
187
187
188
188
this . _readableState = new ReadableState ( options , this , isDuplex ) ;
@@ -216,7 +216,7 @@ Readable.prototype.push = function(chunk, encoding) {
216
216
return readableAddChunk ( this , chunk , encoding , false ) ;
217
217
} ;
218
218
219
- // Unshift should *always* be something directly out of read()
219
+ // Unshift should *always* be something directly out of read().
220
220
Readable . prototype . unshift = function ( chunk , encoding ) {
221
221
return readableAddChunk ( this , chunk , encoding , true ) ;
222
222
} ;
@@ -231,7 +231,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
231
231
encoding = encoding || state . defaultEncoding ;
232
232
if ( addToFront && state . encoding && state . encoding !== encoding ) {
233
233
// When unshifting, if state.encoding is set, we have to save
234
- // the string in the BufferList with the state encoding
234
+ // the string in the BufferList with the state encoding.
235
235
chunk = Buffer . from ( chunk , encoding ) . toString ( state . encoding ) ;
236
236
} else if ( encoding !== state . encoding ) {
237
237
chunk = Buffer . from ( chunk , encoding ) ;
@@ -322,7 +322,7 @@ Readable.prototype.setEncoding = function(enc) {
322
322
StringDecoder = require ( 'string_decoder' ) . StringDecoder ;
323
323
const decoder = new StringDecoder ( enc ) ;
324
324
this . _readableState . decoder = decoder ;
325
- // If setEncoding(null), decoder.encoding equals utf8
325
+ // If setEncoding(null), decoder.encoding equals utf8.
326
326
this . _readableState . encoding = this . _readableState . decoder . encoding ;
327
327
328
328
const buffer = this . _readableState . buffer ;
@@ -338,15 +338,15 @@ Readable.prototype.setEncoding = function(enc) {
338
338
return this ;
339
339
} ;
340
340
341
- // Don't raise the hwm > 1GB
341
+ // Don't raise the hwm > 1GB.
342
342
const MAX_HWM = 0x40000000 ;
343
343
function computeNewHighWaterMark ( n ) {
344
344
if ( n >= MAX_HWM ) {
345
345
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
346
346
n = MAX_HWM ;
347
347
} else {
348
348
// Get the next highest power of 2 to prevent increasing hwm excessively in
349
- // tiny amounts
349
+ // tiny amounts.
350
350
n -- ;
351
351
n |= n >>> 1 ;
352
352
n |= n >>> 2 ;
@@ -366,7 +366,7 @@ function howMuchToRead(n, state) {
366
366
if ( state . objectMode )
367
367
return 1 ;
368
368
if ( NumberIsNaN ( n ) ) {
369
- // Only flow one buffer at a time
369
+ // Only flow one buffer at a time.
370
370
if ( state . flowing && state . length )
371
371
return state . buffer . first ( ) . length ;
372
372
else
@@ -449,7 +449,7 @@ Readable.prototype.read = function(n) {
449
449
let doRead = state . needReadable ;
450
450
debug ( 'need readable' , doRead ) ;
451
451
452
- // If we currently have less than the highWaterMark, then also read some
452
+ // If we currently have less than the highWaterMark, then also read some.
453
453
if ( state . length === 0 || state . length - n < state . highWaterMark ) {
454
454
doRead = true ;
455
455
debug ( 'length less than watermark' , doRead ) ;
@@ -527,7 +527,7 @@ function onEofChunk(stream, state) {
527
527
if ( state . sync ) {
528
528
// If we are sync, wait until next tick to emit the data.
529
529
// Otherwise we risk emitting data in the flow()
530
- // the readable code triggers during a read() call
530
+ // the readable code triggers during a read() call.
531
531
emitReadable ( stream ) ;
532
532
} else {
533
533
// Emit 'readable' now to make sure it gets picked up.
@@ -561,7 +561,7 @@ function emitReadable_(stream) {
561
561
state . emittedReadable = false ;
562
562
}
563
563
564
- // The stream needs another readable event if
564
+ // The stream needs another readable event if:
565
565
// 1. It is not flowing, as the flow mechanism will take
566
566
// care of it.
567
567
// 2. It is not ended.
@@ -680,7 +680,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
680
680
let cleanedUp = false ;
681
681
function cleanup ( ) {
682
682
debug ( 'cleanup' ) ;
683
- // Cleanup event handlers once the pipe is broken
683
+ // Cleanup event handlers once the pipe is broken.
684
684
dest . removeListener ( 'close' , onclose ) ;
685
685
dest . removeListener ( 'finish' , onfinish ) ;
686
686
if ( ondrain ) {
@@ -774,7 +774,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
774
774
src . unpipe ( dest ) ;
775
775
}
776
776
777
- // Tell the dest that it's being piped to
777
+ // Tell the dest that it's being piped to.
778
778
dest . emit ( 'pipe' , src ) ;
779
779
780
780
// Start the flow if it hasn't been started already.
@@ -844,7 +844,7 @@ Readable.prototype.unpipe = function(dest) {
844
844
} ;
845
845
846
846
// Set up data events if they are asked for
847
- // Ensure readable listeners eventually get something
847
+ // Ensure readable listeners eventually get something.
848
848
Readable . prototype . on = function ( ev , fn ) {
849
849
const res = Stream . prototype . on . call ( this , ev , fn ) ;
850
850
const state = this . _readableState ;
@@ -854,7 +854,7 @@ Readable.prototype.on = function(ev, fn) {
854
854
// a few lines down. This is needed to support once('readable').
855
855
state . readableListening = this . listenerCount ( 'readable' ) > 0 ;
856
856
857
- // Try start flowing on next tick if stream isn't explicitly paused
857
+ // Try start flowing on next tick if stream isn't explicitly paused.
858
858
if ( state . flowing !== false )
859
859
this . resume ( ) ;
860
860
} else if ( ev === 'readable' ) {
@@ -917,7 +917,7 @@ function updateReadableListening(self) {
917
917
// the upcoming resume will not flow.
918
918
state . flowing = true ;
919
919
920
- // Crude way to check if we should resume
920
+ // Crude way to check if we should resume.
921
921
} else if ( self . listenerCount ( 'data' ) > 0 ) {
922
922
self . resume ( ) ;
923
923
} else if ( ! state . readableListening ) {
@@ -938,7 +938,7 @@ Readable.prototype.resume = function() {
938
938
debug ( 'resume' ) ;
939
939
// We flow only if there is no one listening
940
940
// for readable, but we still have to call
941
- // resume()
941
+ // resume().
942
942
state . flowing = ! state . readableListening ;
943
943
resume ( this , state ) ;
944
944
}
@@ -1006,7 +1006,7 @@ Readable.prototype.wrap = function(stream) {
1006
1006
if ( state . decoder )
1007
1007
chunk = state . decoder . write ( chunk ) ;
1008
1008
1009
- // Don't skip over falsy values in objectMode
1009
+ // Don't skip over falsy values in objectMode.
1010
1010
if ( state . objectMode && ( chunk === null || chunk === undefined ) )
1011
1011
return ;
1012
1012
else if ( ! state . objectMode && ( ! chunk || ! chunk . length ) )
@@ -1058,7 +1058,7 @@ Readable.prototype[SymbolAsyncIterator] = function() {
1058
1058
1059
1059
// Making it explicit these properties are not enumerable
1060
1060
// because otherwise some prototype manipulation in
1061
- // userland will fail
1061
+ // userland will fail.
1062
1062
ObjectDefineProperties ( Readable . prototype , {
1063
1063
readable : {
1064
1064
get ( ) {
@@ -1135,13 +1135,13 @@ ObjectDefineProperties(Readable.prototype, {
1135
1135
} ,
1136
1136
set ( value ) {
1137
1137
// We ignore the value if the stream
1138
- // has not been initialized yet
1138
+ // has not been initialized yet.
1139
1139
if ( ! this . _readableState ) {
1140
1140
return ;
1141
1141
}
1142
1142
1143
1143
// Backward compatibility, the user is explicitly
1144
- // managing destroyed
1144
+ // managing destroyed.
1145
1145
this . _readableState . destroyed = value ;
1146
1146
}
1147
1147
} ,
@@ -1178,15 +1178,15 @@ Readable._fromList = fromList;
1178
1178
// This function is designed to be inlinable, so please take care when making
1179
1179
// changes to the function body.
1180
1180
function fromList ( n , state ) {
1181
- // nothing buffered
1181
+ // nothing buffered.
1182
1182
if ( state . length === 0 )
1183
1183
return null ;
1184
1184
1185
1185
let ret ;
1186
1186
if ( state . objectMode )
1187
1187
ret = state . buffer . shift ( ) ;
1188
1188
else if ( ! n || n >= state . length ) {
1189
- // Read it all, truncate the list
1189
+ // Read it all, truncate the list.
1190
1190
if ( state . decoder )
1191
1191
ret = state . buffer . join ( '' ) ;
1192
1192
else if ( state . buffer . length === 1 )
@@ -1195,7 +1195,7 @@ function fromList(n, state) {
1195
1195
ret = state . buffer . concat ( state . length ) ;
1196
1196
state . buffer . clear ( ) ;
1197
1197
} else {
1198
- // read part of list
1198
+ // read part of list.
1199
1199
ret = state . buffer . consume ( n , state . decoder ) ;
1200
1200
}
1201
1201
@@ -1224,7 +1224,7 @@ function endReadableNT(state, stream) {
1224
1224
process . nextTick ( endWritableNT , state , stream ) ;
1225
1225
} else if ( state . autoDestroy ) {
1226
1226
// In case of duplex streams we need a way to detect
1227
- // if the writable side is ready for autoDestroy as well
1227
+ // if the writable side is ready for autoDestroy as well.
1228
1228
const wState = stream . _writableState ;
1229
1229
const autoDestroy = ! wState || (
1230
1230
wState . autoDestroy &&
0 commit comments