diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index fe2281df471dc7..07a16175ffcd73 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -83,7 +83,7 @@ ObjectDefineProperties(Duplex.prototype, { }, set(value) { // Backward compatibility, the user is explicitly - // managing destroyed + // managing destroyed. if (this._readableState && this._writableState) { this._readableState.destroyed = value; this._writableState.destroyed = value; diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index ef847c110edc23..9c1441dd9ce405 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -94,7 +94,7 @@ function ReadableState(options, stream, isDuplex) { isDuplex = stream instanceof Stream.Duplex; // Object stream flag. Used to make read(n) ignore n and to - // make all the buffer merging and length checks go away + // make all the buffer merging and length checks go away. this.objectMode = !!(options && options.objectMode); if (isDuplex) @@ -109,7 +109,7 @@ function ReadableState(options, stream, isDuplex) { // A linked list is used to store data chunks instead of an array because the // linked list can remove elements from the beginning faster than - // array.shift() + // array.shift(). this.buffer = new BufferList(); this.length = 0; this.pipes = []; @@ -132,16 +132,16 @@ function ReadableState(options, stream, isDuplex) { this.resumeScheduled = false; this[kPaused] = null; - // True if the error was already emitted and should not be thrown again + // True if the error was already emitted and should not be thrown again. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true. this.emitClose = !options || options.emitClose !== false; - // Should .destroy() be called after 'end' (and potentially 'finish') + // Should .destroy() be called after 'end' (and potentially 'finish'). this.autoDestroy = !options || options.autoDestroy !== false; - // Has it been destroyed + // Has it been destroyed. this.destroyed = false; // Indicates whether the stream has errored. @@ -156,11 +156,11 @@ function ReadableState(options, stream, isDuplex) { this.defaultEncoding = (options && options.defaultEncoding) || 'utf8'; // Ref the piped dest which we need a drain event on it - // type: null | Writable | Set + // type: null | Writable | Set. this.awaitDrainWriters = null; this.multiAwaitDrain = false; - // If true, a maybeReadMore has been scheduled + // If true, a maybeReadMore has been scheduled. this.readingMore = false; this.decoder = null; @@ -179,7 +179,7 @@ function Readable(options) { return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside - // the ReadableState constructor, at least with V8 6.5 + // the ReadableState constructor, at least with V8 6.5. const isDuplex = this instanceof Stream.Duplex; this._readableState = new ReadableState(options, this, isDuplex); @@ -213,7 +213,7 @@ Readable.prototype.push = function(chunk, encoding) { return readableAddChunk(this, chunk, encoding, false); }; -// Unshift should *always* be something directly out of read() +// Unshift should *always* be something directly out of read(). Readable.prototype.unshift = function(chunk, encoding) { return readableAddChunk(this, chunk, encoding, true); }; @@ -228,7 +228,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) { encoding = encoding || state.defaultEncoding; if (addToFront && state.encoding && state.encoding !== encoding) { // When unshifting, if state.encoding is set, we have to save - // the string in the BufferList with the state encoding + // the string in the BufferList with the state encoding. chunk = Buffer.from(chunk, encoding).toString(state.encoding); } else if (encoding !== state.encoding) { chunk = Buffer.from(chunk, encoding); @@ -319,7 +319,7 @@ Readable.prototype.setEncoding = function(enc) { StringDecoder = require('string_decoder').StringDecoder; const decoder = new StringDecoder(enc); this._readableState.decoder = decoder; - // If setEncoding(null), decoder.encoding equals utf8 + // If setEncoding(null), decoder.encoding equals utf8. this._readableState.encoding = this._readableState.decoder.encoding; const buffer = this._readableState.buffer; @@ -335,7 +335,7 @@ Readable.prototype.setEncoding = function(enc) { return this; }; -// Don't raise the hwm > 1GB +// Don't raise the hwm > 1GB. const MAX_HWM = 0x40000000; function computeNewHighWaterMark(n) { if (n >= MAX_HWM) { @@ -343,7 +343,7 @@ function computeNewHighWaterMark(n) { n = MAX_HWM; } else { // Get the next highest power of 2 to prevent increasing hwm excessively in - // tiny amounts + // tiny amounts. n--; n |= n >>> 1; n |= n >>> 2; @@ -363,7 +363,7 @@ function howMuchToRead(n, state) { if (state.objectMode) return 1; if (NumberIsNaN(n)) { - // Only flow one buffer at a time + // Only flow one buffer at a time. if (state.flowing && state.length) return state.buffer.first().length; else @@ -446,7 +446,7 @@ Readable.prototype.read = function(n) { let doRead = state.needReadable; debug('need readable', doRead); - // If we currently have less than the highWaterMark, then also read some + // If we currently have less than the highWaterMark, then also read some. if (state.length === 0 || state.length - n < state.highWaterMark) { doRead = true; debug('length less than watermark', doRead); @@ -524,7 +524,7 @@ function onEofChunk(stream, state) { if (state.sync) { // If we are sync, wait until next tick to emit the data. // Otherwise we risk emitting data in the flow() - // the readable code triggers during a read() call + // the readable code triggers during a read() call. emitReadable(stream); } else { // Emit 'readable' now to make sure it gets picked up. @@ -558,7 +558,7 @@ function emitReadable_(stream) { state.emittedReadable = false; } - // The stream needs another readable event if + // The stream needs another readable event if: // 1. It is not flowing, as the flow mechanism will take // care of it. // 2. It is not ended. @@ -677,7 +677,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { let cleanedUp = false; function cleanup() { debug('cleanup'); - // Cleanup event handlers once the pipe is broken + // Cleanup event handlers once the pipe is broken. dest.removeListener('close', onclose); dest.removeListener('finish', onfinish); if (ondrain) { @@ -771,7 +771,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { src.unpipe(dest); } - // Tell the dest that it's being piped to + // Tell the dest that it's being piped to. dest.emit('pipe', src); // Start the flow if it hasn't been started already. @@ -841,7 +841,7 @@ Readable.prototype.unpipe = function(dest) { }; // Set up data events if they are asked for -// Ensure readable listeners eventually get something +// Ensure readable listeners eventually get something. Readable.prototype.on = function(ev, fn) { const res = Stream.prototype.on.call(this, ev, fn); const state = this._readableState; @@ -851,7 +851,7 @@ Readable.prototype.on = function(ev, fn) { // a few lines down. This is needed to support once('readable'). state.readableListening = this.listenerCount('readable') > 0; - // Try start flowing on next tick if stream isn't explicitly paused + // Try start flowing on next tick if stream isn't explicitly paused. if (state.flowing !== false) this.resume(); } else if (ev === 'readable') { @@ -914,7 +914,7 @@ function updateReadableListening(self) { // the upcoming resume will not flow. state.flowing = true; - // Crude way to check if we should resume + // Crude way to check if we should resume. } else if (self.listenerCount('data') > 0) { self.resume(); } else if (!state.readableListening) { @@ -935,7 +935,7 @@ Readable.prototype.resume = function() { debug('resume'); // We flow only if there is no one listening // for readable, but we still have to call - // resume() + // resume(). state.flowing = !state.readableListening; resume(this, state); } @@ -1003,7 +1003,7 @@ Readable.prototype.wrap = function(stream) { if (state.decoder) chunk = state.decoder.write(chunk); - // Don't skip over falsy values in objectMode + // Don't skip over falsy values in objectMode. if (state.objectMode && (chunk === null || chunk === undefined)) return; else if (!state.objectMode && (!chunk || !chunk.length)) @@ -1055,7 +1055,7 @@ Readable.prototype[SymbolAsyncIterator] = function() { // Making it explicit these properties are not enumerable // because otherwise some prototype manipulation in -// userland will fail +// userland will fail. ObjectDefineProperties(Readable.prototype, { readable: { get() { @@ -1132,13 +1132,13 @@ ObjectDefineProperties(Readable.prototype, { }, set(value) { // We ignore the value if the stream - // has not been initialized yet + // has not been initialized yet. if (!this._readableState) { return; } // Backward compatibility, the user is explicitly - // managing destroyed + // managing destroyed. this._readableState.destroyed = value; } }, @@ -1175,7 +1175,7 @@ Readable._fromList = fromList; // This function is designed to be inlinable, so please take care when making // changes to the function body. function fromList(n, state) { - // nothing buffered + // nothing buffered. if (state.length === 0) return null; @@ -1183,7 +1183,7 @@ function fromList(n, state) { if (state.objectMode) ret = state.buffer.shift(); else if (!n || n >= state.length) { - // Read it all, truncate the list + // Read it all, truncate the list. if (state.decoder) ret = state.buffer.join(''); else if (state.buffer.length === 1) @@ -1192,7 +1192,7 @@ function fromList(n, state) { ret = state.buffer.concat(state.length); state.buffer.clear(); } else { - // read part of list + // read part of list. ret = state.buffer.consume(n, state.decoder); } @@ -1221,7 +1221,7 @@ function endReadableNT(state, stream) { process.nextTick(endWritableNT, state, stream); } else if (state.autoDestroy) { // In case of duplex streams we need a way to detect - // if the writable side is ready for autoDestroy as well + // if the writable side is ready for autoDestroy as well. const wState = stream._writableState; const autoDestroy = !wState || ( wState.autoDestroy && diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 1d02e2ff8e27f6..57b1b9cc92fb32 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -83,21 +83,21 @@ function WritableState(options, stream, isDuplex) { // The point at which write() starts returning false // Note: 0 is a valid value, means that we always return false if - // the entire buffer is not flushed immediately on write() + // the entire buffer is not flushed immediately on write(). this.highWaterMark = options ? getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex) : getDefaultHighWaterMark(false); - // if _final has been called + // if _final has been called. this.finalCalled = false; // drain event flag. this.needDrain = false; // At the start of calling end() this.ending = false; - // When end() has been called, and returned + // When end() has been called, and returned. this.ended = false; - // When 'finish' is emitted + // When 'finish' is emitted. this.finished = false; // Has it been destroyed @@ -122,7 +122,7 @@ function WritableState(options, stream, isDuplex) { // A flag to see when we're in the middle of a write. this.writing = false; - // When true all writes will be buffered until .uncork() call + // When true all writes will be buffered until .uncork() call. this.corked = 0; // A flag to be able to tell if the onwrite cb is called immediately, @@ -136,10 +136,10 @@ function WritableState(options, stream, isDuplex) { // end up in an overlapped onwrite situation. this.bufferProcessing = false; - // The callback that's passed to _write(chunk,cb) + // The callback that's passed to _write(chunk, cb). this.onwrite = onwrite.bind(undefined, stream); - // The callback that the user supplies to write(chunk,encoding,cb) + // The callback that the user supplies to write(chunk, encoding, cb). this.writecb = null; // The amount that is being written when _write is called. @@ -152,20 +152,20 @@ function WritableState(options, stream, isDuplex) { resetBuffer(this); // Number of pending user-supplied write callbacks - // this must be 0 before 'finish' can be emitted + // this must be 0 before 'finish' can be emitted. this.pendingcb = 0; // Emit prefinish if the only thing we're waiting for is _write cbs - // This is relevant for synchronous Transform streams + // This is relevant for synchronous Transform streams. this.prefinished = false; - // True if the error was already emitted and should not be thrown again + // True if the error was already emitted and should not be thrown again. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true. this.emitClose = !options || options.emitClose !== false; - // Should .destroy() be called after 'finish' (and potentially 'end') + // Should .destroy() be called after 'finish' (and potentially 'end'). this.autoDestroy = !options || options.autoDestroy !== false; // Indicates whether the stream has errored. When true all write() calls @@ -225,7 +225,7 @@ function Writable(options) { // `_writableState` that would lead to infinite recursion. // Checking for a Stream.Duplex instance is faster here instead of inside - // the WritableState constructor, at least with V8 6.5 + // the WritableState constructor, at least with V8 6.5. const isDuplex = (this instanceof Stream.Duplex); if (!isDuplex && !realHasInstance.call(Writable, this)) @@ -480,7 +480,7 @@ function errorBuffer(state, err) { resetBuffer(state); } -// If there's something in the buffer waiting, then process it +// If there's something in the buffer waiting, then process it. function clearBuffer(stream, state) { if (state.corked || state.bufferProcessing) { return; @@ -557,7 +557,7 @@ Writable.prototype.end = function(chunk, encoding, cb) { if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); - // .end() fully uncorks + // .end() fully uncorks. if (state.corked) { state.corked = 1; this.uncork(); @@ -649,7 +649,7 @@ function finish(stream, state) { if (state.autoDestroy) { // In case of duplex streams we need a way to detect - // if the readable side is ready for autoDestroy as well + // if the readable side is ready for autoDestroy as well. const rState = stream._readableState; const autoDestroy = !rState || ( rState.autoDestroy && @@ -690,7 +690,7 @@ ObjectDefineProperties(Writable.prototype, { return this._writableState ? this._writableState.destroyed : false; }, set(value) { - // Backward compatibility, the user is explicitly managing destroyed + // Backward compatibility, the user is explicitly managing destroyed. if (this._writableState) { this._writableState.destroyed = value; }