Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6834ca1

Browse filesBrowse files
Renegade334aduh95
authored andcommitted
stream: rename Duplex.toWeb() type option to readableType
PR-URL: #61632 Refs: #58664 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com>
1 parent 0312db9 commit 6834ca1
Copy full SHA for 6834ca1

4 files changed

+41-8Lines changed: 41 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/deprecations.md‎

Copy file name to clipboardExpand all lines: doc/api/deprecations.md
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -4320,6 +4320,21 @@ import { opendir } from 'node:fs/promises';
43204320
}
43214321
```
43224322
4323+
### DEP0201: Passing `options.type` to `Duplex.toWeb()`
4324+
4325+
<!-- YAML
4326+
changes:
4327+
- version: REPLACEME
4328+
pr-url: https://github.com/nodejs/node/pull/61632
4329+
description: Documentation-only deprecation.
4330+
-->
4331+
4332+
Type: Documentation-only
4333+
4334+
Passing the `type` option to [`Duplex.toWeb()`][] is deprecated. To specify the
4335+
type of the readable half of the constructed readable-writable pair, use the
4336+
`readableType` option instead.
4337+
43234338
[DEP0142]: #dep0142-repl_builtinlibs
43244339
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
43254340
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -4338,6 +4353,7 @@ import { opendir } from 'node:fs/promises';
43384353
[`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj
43394354
[`Cipheriv`]: crypto.md#class-cipheriv
43404355
[`Decipheriv`]: crypto.md#class-decipheriv
4356+
[`Duplex.toWeb()`]: stream.md#streamduplextowebstreamduplex-options
43414357
[`Error.isError`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
43424358
[`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand
43434359
[`ReadStream.open()`]: fs.md#class-fsreadstream
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+10-3Lines changed: 10 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,8 @@ changes:
32033203
If no value is provided, the size will be `1` for all the chunks.
32043204
* `chunk` {any}
32053205
* Returns: {number}
3206-
* `type` {string} Must be 'bytes' or undefined.
3206+
* `type` {string} Specifies the type of the created `ReadableStream`. Must be
3207+
`'bytes'` or undefined.
32073208
* Returns: {ReadableStream}
32083209

32093210
### `stream.Writable.fromWeb(writableStream[, options])`
@@ -3376,17 +3377,23 @@ duplex.once('readable', () => console.log('readable', duplex.read()));
33763377
<!-- YAML
33773378
added: v17.0.0
33783379
changes:
3380+
- version: REPLACEME
3381+
pr-url: https://github.com/nodejs/node/pull/61632
3382+
description: Added the 'readableType' option to specify the ReadableStream
3383+
type. The 'type' option is deprecated.
33793384
- version: v24.14.0
33803385
pr-url: https://github.com/nodejs/node/pull/58664
3381-
description: Add 'type' option to specify 'bytes'.
3386+
description: Added the 'type' option to specify the ReadableStream type.
33823387
- version: v24.0.0
33833388
pr-url: https://github.com/nodejs/node/pull/57513
33843389
description: Marking the API stable.
33853390
-->
33863391

33873392
* `streamDuplex` {stream.Duplex}
33883393
* `options` {Object}
3389-
* `type` {string} Must be 'bytes' or undefined.
3394+
* `readableType` {string} Specifies the type of the `ReadableStream` half of
3395+
the created readable-writable pair. Must be `'bytes'` or undefined.
3396+
(`options.type` is a deprecated alias for this option.)
33903397
* Returns: {Object}
33913398
* `readable` {ReadableStream}
33923399
* `writable` {WritableStream}
Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj
624624

625625
/**
626626
* @param {Duplex} duplex
627-
* @param {{ type?: 'bytes' }} [options]
627+
* @param {{ readableType?: 'bytes' }} [options]
628628
* @returns {ReadableWritablePair}
629629
*/
630630
function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) {
@@ -641,9 +641,15 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) {
641641

642642
validateObject(options, 'options');
643643

644+
const readableOptions = {
645+
__proto__: null,
646+
// DEP0201: 'options.type' is a deprecated alias for 'options.readableType'
647+
type: options.readableType ?? options.type,
648+
};
649+
644650
if (isDestroyed(duplex)) {
645651
const writable = new WritableStream();
646-
const readable = new ReadableStream({ type: options.type });
652+
const readable = new ReadableStream({ type: readableOptions.type });
647653
writable.close();
648654
readable.cancel();
649655
return { readable, writable };
@@ -659,8 +665,8 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) {
659665

660666
const readable =
661667
isReadable(duplex) ?
662-
newReadableStreamFromStreamReadable(duplex, options) :
663-
new ReadableStream({ type: options.type });
668+
newReadableStreamFromStreamReadable(duplex, readableOptions) :
669+
new ReadableStream({ type: readableOptions.type });
664670

665671
if (!isReadable(duplex))
666672
readable.cancel();
Collapse file

‎test/parallel/test-stream-duplex.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-duplex.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ process.on('exit', () => {
147147
})
148148
});
149149

150-
const { writable, readable } = Duplex.toWeb(duplex, { type: 'bytes' });
150+
const { writable, readable } = Duplex.toWeb(duplex, { readableType: 'bytes' });
151151
writable.getWriter().write(dataToWrite);
152152
const data = new Uint8Array(dataToRead.length);
153153
readable.getReader({ mode: 'byob' }).read(data).then(common.mustCall((result) => {
154154
assert.deepStrictEqual(Buffer.from(result.value), dataToRead);
155155
}));
156+
157+
// Ensure that the originally-named `options.type` still works as an alias for `options.readableType`
158+
// `getReader({ mode: 'byob' })` throws if the underlying ReadableStream is not a byte stream
159+
Duplex.toWeb(duplex, { type: 'bytes' }).readable.getReader({ mode: 'byob' });
156160
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.