From cf7248766717168eab46d886fea4f0f0fe13b761 Mon Sep 17 00:00:00 2001 From: Jay Patel <0807Jpatel@gmail.com> Date: Sun, 10 May 2020 18:23:56 -0400 Subject: [PATCH 1/9] feat(stream): added mutable highwatermark and object mode --- doc/api/stream.md | 36 ++++++++++++++ lib/_stream_readable.js | 35 +++++++++++++- lib/_stream_writable.js | 28 ++++++++++- .../test-stream-readable-hwm-mutable.js | 45 ++++++++++++++++++ .../test-stream-writable-hwm-mutable.js | 47 +++++++++++++++++++ 5 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-stream-readable-hwm-mutable.js create mode 100644 test/parallel/test-stream-writable-hwm-mutable.js diff --git a/doc/api/stream.md b/doc/api/stream.md index 6229704eb91bc4..41f77dd3a1096d 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -568,6 +568,24 @@ added: v12.3.0 Getter for the property `objectMode` of a given `Writable` stream. +##### `writable.updateWritableHighwaterMark(highwaterMark)` + + +* `highwaterMark` {number} new highwaterMark + +Update the value of `highWaterMark` of a given `Writable` stream. + +##### `writable.updateWritableObjectMode(objectMode)` + + +* `objectMode` {boolean} new objectMode + +Update the value of `objectMode` of a given `Writable` stream. + ##### `writable.write(chunk[, encoding][, callback])` + +* `highwaterMark` {number} new highwaterMark + +Update the value of `highWaterMark` of a given `Readable` stream. + +##### `readable.updateReadableObjectMode(objectMode)` + + +* `objectMode` {boolean} new objectMode + +Update the value of `objectMode` of a given `Readable` stream. + ##### `readable.resume()` * `highwaterMark` {number} new highwaterMark @@ -579,7 +579,7 @@ Update the value of `highWaterMark` of a given `Writable` stream. ##### `writable.updateWritableObjectMode(objectMode)` * `objectMode` {boolean} new objectMode @@ -1231,7 +1231,7 @@ Getter for the property `objectMode` of a given `Readable` stream. ##### `readable.updateReadableHighWaterMark(highwaterMark)` * `highwaterMark` {number} new highwaterMark @@ -1240,7 +1240,7 @@ Update the value of `highWaterMark` of a given `Readable` stream. ##### `readable.updateReadableObjectMode(objectMode)` * `objectMode` {boolean} new objectMode diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index fe7bf79e40eaab..f59f273f2ba708 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -37,6 +37,7 @@ const { module.exports = Writable; Writable.WritableState = WritableState; +const debug = require('internal/util/debuglog').debuglog('stream'); const EE = require('events'); const Stream = require('stream'); const { Buffer } = require('buffer'); @@ -264,6 +265,7 @@ Writable.prototype.pipe = function() { }; Writable.prototype.write = function(chunk, encoding, cb) { + debug('write', chunk, encoding); const state = this._writableState; if (state.updateHighwaterMark !== null) { From 8ab362bbc79271cdff8aa56295b94167e861d3cd Mon Sep 17 00:00:00 2001 From: Jay Patel <0807Jpatel@gmail.com> Date: Mon, 11 May 2020 07:42:33 -0400 Subject: [PATCH 3/9] fix: remove debug statements from writable stream --- lib/_stream_writable.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index f59f273f2ba708..fe7bf79e40eaab 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -37,7 +37,6 @@ const { module.exports = Writable; Writable.WritableState = WritableState; -const debug = require('internal/util/debuglog').debuglog('stream'); const EE = require('events'); const Stream = require('stream'); const { Buffer } = require('buffer'); @@ -265,7 +264,6 @@ Writable.prototype.pipe = function() { }; Writable.prototype.write = function(chunk, encoding, cb) { - debug('write', chunk, encoding); const state = this._writableState; if (state.updateHighwaterMark !== null) { From 5ca4f8c8b25cb52b0fa187d33029695419b8bc6a Mon Sep 17 00:00:00 2001 From: Jay Patel <0807Jpatel@gmail.com> Date: Tue, 12 May 2020 20:19:37 -0400 Subject: [PATCH 4/9] chore: removed mutable objectMode and highWaterMark uses setter --- doc/api/stream.md | 54 +++++++------------ lib/_stream_readable.js | 31 +++-------- lib/_stream_writable.js | 23 +++----- .../test-stream-readable-hwm-mutable.js | 15 +++--- .../test-stream-writable-hwm-mutable.js | 21 ++++---- 5 files changed, 48 insertions(+), 96 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 2b5ddf17a6f19b..6b38427e75ff84 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -548,6 +548,15 @@ added: v9.3.0 Return the value of `highWaterMark` passed when constructing this `Writable`. +##### `writable.writableHighWaterMark` + + +* `highwaterMark` {number} new highwaterMark + +Update the value of `highWaterMark` of a given `Writable` stream. + ##### `writable.writableLength` - -* `highwaterMark` {number} new highwaterMark - -Update the value of `highWaterMark` of a given `Writable` stream. - -##### `writable.updateWritableObjectMode(objectMode)` - - -* `objectMode` {boolean} new objectMode - -Update the value of `objectMode` of a given `Writable` stream. - ##### `writable.write(chunk[, encoding][, callback])` + +* `highwaterMark` {number} new highwaterMark + +Update the value of `highWaterMark` of a given `Readable` stream. + ##### `readable.readableLength` - -* `highwaterMark` {number} new highwaterMark - -Update the value of `highWaterMark` of a given `Readable` stream. - -##### `readable.updateReadableObjectMode(objectMode)` - - -* `objectMode` {boolean} new objectMode - -Update the value of `objectMode` of a given `Readable` stream. - ##### `readable.resume()` - -* {number} - -Return the value of `highWaterMark` passed when constructing this -`Writable`. - ##### `writable.writableHighWaterMark` -* `highwaterMark` {number} new highwaterMark +* {number} -Update the value of `highWaterMark` of a given `Writable` stream. +Get or set the value of `highWaterMark` for a given `Writable` stream. ##### `writable.writableLength` - -* {number} - -Returns the value of `highWaterMark` passed when constructing this -`Readable`. - ##### `readable.readableHighWaterMark` -* `highwaterMark` {number} new highwaterMark +* {number} -Update the value of `highWaterMark` of a given `Readable` stream. +Get or set the value of `highWaterMark` for a given `Readable` stream. ##### `readable.readableLength` + +An attempt was made to update `readableHighWarkMark` from [`stream.read()`][] +function. + + +### `ERR_STREAM_UPDATING_HIGHWATERMARK_IN_WRITE` + + +An attempt was made to update `writableHighWaterMark` from [`stream.write()`][] +function. + ### `ERR_STREAM_WRAP` @@ -2569,6 +2587,7 @@ such as `process.stdout.on('data')`. [`stream.push()`]: stream.html#stream_readable_push_chunk_encoding [`stream.unshift()`]: stream.html#stream_readable_unshift_chunk_encoding [`stream.write()`]: stream.html#stream_writable_write_chunk_encoding_callback +[`stream.read()`]: stream.html#stream_readable_read_size [`subprocess.kill()`]: child_process.html#child_process_subprocess_kill_signal [`subprocess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback [`util.getSystemErrorName(error.errno)`]: util.html#util_util_getsystemerrorname_err diff --git a/doc/api/stream.md b/doc/api/stream.md index 441f4a87870686..96353ffd795703 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -545,7 +545,8 @@ added: REPLACEME * {number} -Get or set the value of `highWaterMark` for a given `Writable` stream. +Get or set the value of `highWaterMark` for a given `Writable` stream. Should +not update `writableHighWaterMark` from [`stream.write`][stream-write] ##### `writable.writableLength`