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 608736e

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 7d9cc5d commit 608736e
Copy full SHA for 608736e

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
@@ -4400,6 +4400,21 @@ import { opendir } from 'node:fs/promises';
44004400
}
44014401
```
44024402
4403+
### DEP0201: Passing `options.type` to `Duplex.toWeb()`
4404+
4405+
<!-- YAML
4406+
changes:
4407+
- version: REPLACEME
4408+
pr-url: https://github.com/nodejs/node/pull/61632
4409+
description: Documentation-only deprecation.
4410+
-->
4411+
4412+
Type: Documentation-only
4413+
4414+
Passing the `type` option to [`Duplex.toWeb()`][] is deprecated. To specify the
4415+
type of the readable half of the constructed readable-writable pair, use the
4416+
`readableType` option instead.
4417+
44034418
[DEP0142]: #dep0142-repl_builtinlibs
44044419
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
44054420
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -4418,6 +4433,7 @@ import { opendir } from 'node:fs/promises';
44184433
[`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj
44194434
[`Cipheriv`]: crypto.md#class-cipheriv
44204435
[`Decipheriv`]: crypto.md#class-decipheriv
4436+
[`Duplex.toWeb()`]: stream.md#streamduplextowebstreamduplex-options
44214437
[`Error.isError`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
44224438
[`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand
44234439
[`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
@@ -3219,7 +3219,8 @@ changes:
32193219
If no value is provided, the size will be `1` for all the chunks.
32203220
* `chunk` {any}
32213221
* Returns: {number}
3222-
* `type` {string} Must be 'bytes' or undefined.
3222+
* `type` {string} Specifies the type of the created `ReadableStream`. Must be
3223+
`'bytes'` or undefined.
32233224
* Returns: {ReadableStream}
32243225

32253226
### `stream.Writable.fromWeb(writableStream[, options])`
@@ -3398,9 +3399,13 @@ duplex.once('readable', () => console.log('readable', duplex.read()));
33983399
<!-- YAML
33993400
added: v17.0.0
34003401
changes:
3402+
- version: REPLACEME
3403+
pr-url: https://github.com/nodejs/node/pull/61632
3404+
description: Added the 'readableType' option to specify the ReadableStream
3405+
type. The 'type' option is deprecated.
34013406
- version: v25.4.0
34023407
pr-url: https://github.com/nodejs/node/pull/58664
3403-
description: Add 'type' option to specify 'bytes'.
3408+
description: Added the 'type' option to specify the ReadableStream type.
34043409
- version:
34053410
- v24.0.0
34063411
- v22.17.0
@@ -3410,7 +3415,9 @@ changes:
34103415

34113416
* `streamDuplex` {stream.Duplex}
34123417
* `options` {Object}
3413-
* `type` {string} Must be 'bytes' or undefined.
3418+
* `readableType` {string} Specifies the type of the `ReadableStream` half of
3419+
the created readable-writable pair. Must be `'bytes'` or undefined.
3420+
(`options.type` is a deprecated alias for this option.)
34143421
* Returns: {Object}
34153422
* `readable` {ReadableStream}
34163423
* `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.