Skip to content

Commit

Permalink
stream: consistent punctuation
Browse files Browse the repository at this point in the history
Cleanup comments to use consistent punctuation.

PR-URL: #32934
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
ronag authored and BethGriggs committed Apr 28, 2020
1 parent 988c2fe commit 4c10b5f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 31 additions & 31 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = [];
Expand All @@ -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.
Expand All @@ -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<Writable>
// type: null | Writable | Set<Writable>.
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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
};
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -335,15 +335,15 @@ 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) {
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand 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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
},
Expand Down Expand Up @@ -1175,15 +1175,15 @@ 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;

let ret;
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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 &&
Expand Down
32 changes: 16 additions & 16 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4c10b5f

Please sign in to comment.