Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stream: extend strategy option using an object to allow extensibility
  • Loading branch information
Warkanlock committed Jun 21, 2022
commit b48a89d91cddf6aefd450ec3926fb8589285bb8b
3 changes: 2 additions & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,8 @@ added: v17.0.0
> Stability: 1 - Experimental

* `streamReadable` {stream.Readable}
* `strategy` {queuingstrategies.QueuingStrategy}
* `options` {Object}
* `strategy` {QueuingStrategy}
Comment thread
Warkanlock marked this conversation as resolved.
Outdated
* Returns: {ReadableStream}

### `stream.Writable.fromWeb(writableStream[, options])`
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,10 @@ Readable.fromWeb = function(readableStream, options) {
options);
};

Readable.toWeb = function(streamReadable, strategy = null) {
return lazyWebStreams().newReadableStreamFromStreamReadable(streamReadable, strategy);
Readable.toWeb = function(streamReadable, options) {
return lazyWebStreams().newReadableStreamFromStreamReadable(
streamReadable,
options);
};

Readable.wrap = function(src, options) {
Expand Down
10 changes: 8 additions & 2 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ function newStreamWritableFromWritableStream(writableStream, options = kEmptyObj
/**
* @typedef {import('./queuingstrategies').QueuingStrategy} QueuingStrategy
* @param {Readable} streamReadable
* @param {QueuingStrategy} [queuingStrategy]
* @param {{
* strategy : QueuingStrategy
* }} [options]
* @returns {ReadableStream}
*/
function newReadableStreamFromStreamReadable(streamReadable, queuingStrategy = null) {
function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObject) {
// Not using the internal/streams/utils isReadableNodeStream utility
// here because it will return false if streamReadable is a Duplex
// whose readable option is false. For a Duplex that is not readable,
Expand All @@ -388,6 +390,10 @@ function newReadableStreamFromStreamReadable(streamReadable, queuingStrategy = n
// back to a minimal strategy that just specifies the highWaterMark
// and no size algorithm. Using a ByteLengthQueuingStrategy here
// is unnecessary.

// If there is an strategy available, use it. Otherwise, fallback to default behavior
Comment thread
Warkanlock marked this conversation as resolved.
Outdated
const queuingStrategy = options?.strategy;

const strategy = queuingStrategy ?
Comment thread
Warkanlock marked this conversation as resolved.
Outdated
queuingStrategy :
objectMode ?
Expand Down