Skip to content

Commit 8fa8026

Browse files
committed
stream: extend strategy option using an object to allow extensibility
1 parent 1e27fe9 commit 8fa8026

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

doc/api/stream.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,8 @@ added: v17.0.0
28162816
> Stability: 1 - Experimental
28172817
28182818
* `streamReadable` {stream.Readable}
2819-
* `strategy` {queuingstrategies.QueuingStrategy}
2819+
* `options` {Object}
2820+
* `strategy` {QueuingStrategy}
28202821
* Returns: {ReadableStream}
28212822

28222823
### `stream.Writable.fromWeb(writableStream[, options])`

lib/internal/streams/readable.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,10 @@ Readable.fromWeb = function(readableStream, options) {
14051405
options);
14061406
};
14071407

1408-
Readable.toWeb = function(streamReadable, strategy = null) {
1409-
return lazyWebStreams().newReadableStreamFromStreamReadable(streamReadable, strategy);
1408+
Readable.toWeb = function(streamReadable, options) {
1409+
return lazyWebStreams().newReadableStreamFromStreamReadable(
1410+
streamReadable,
1411+
options);
14101412
};
14111413

14121414
Readable.wrap = function(src, options) {

lib/internal/webstreams/adapters.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,12 @@ function newStreamWritableFromWritableStream(writableStream, options = kEmptyObj
361361
/**
362362
* @typedef {import('./queuingstrategies').QueuingStrategy} QueuingStrategy
363363
* @param {Readable} streamReadable
364-
* @param {QueuingStrategy} [queuingStrategy]
364+
* @param {{
365+
* strategy : QueuingStrategy
366+
* }} [options]
365367
* @returns {ReadableStream}
366368
*/
367-
function newReadableStreamFromStreamReadable(streamReadable, queuingStrategy = null) {
369+
function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObject) {
368370
// Not using the internal/streams/utils isReadableNodeStream utility
369371
// here because it will return false if streamReadable is a Duplex
370372
// whose readable option is false. For a Duplex that is not readable,
@@ -388,6 +390,10 @@ function newReadableStreamFromStreamReadable(streamReadable, queuingStrategy = n
388390
// back to a minimal strategy that just specifies the highWaterMark
389391
// and no size algorithm. Using a ByteLengthQueuingStrategy here
390392
// is unnecessary.
393+
394+
// If there is an strategy available, use it. Otherwise, fallback to default behavior
395+
const queuingStrategy = options?.strategy;
396+
391397
const strategy = queuingStrategy ?
392398
queuingStrategy :
393399
objectMode ?

0 commit comments

Comments
 (0)