GeezerVison is showing github.com — stream: rename `Duplex.toWeb()` type option to `readableType` · nodejs/node@608736e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -4400,6 +4400,21 @@ import { opendir } from 'node:fs/promises'; | 4400 | 4400 | } | 4401 | 4401 | ``` | 4402 | 4402 |
| | 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 | +
| 4403 | 4418 | [DEP0142]: #dep0142-repl_builtinlibs | 4404 | 4419 | [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf | 4405 | 4420 | [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 | @@ -4418,6 +4433,7 @@ import { opendir } from 'node:fs/promises'; | 4418 | 4433 | [`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj | 4419 | 4434 | [`Cipheriv`]: crypto.md#class-cipheriv | 4420 | 4435 | [`Decipheriv`]: crypto.md#class-decipheriv | | 4436 | +[`Duplex.toWeb()`]: stream.md#streamduplextowebstreamduplex-options | 4421 | 4437 | [`Error.isError`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError | 4422 | 4438 | [`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand | 4423 | 4439 | [`ReadStream.open()`]: fs.md#class-fsreadstream | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -3219,7 +3219,8 @@ changes: | 3219 | 3219 | If no value is provided, the size will be `1` for all the chunks. | 3220 | 3220 | * `chunk` {any} | 3221 | 3221 | * 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. | 3223 | 3224 | * Returns: {ReadableStream} | 3224 | 3225 |
| 3225 | 3226 | ### `stream.Writable.fromWeb(writableStream[, options])` | @@ -3398,9 +3399,13 @@ duplex.once('readable', () => console.log('readable', duplex.read())); | 3398 | 3399 | <!-- YAML | 3399 | 3400 | added: v17.0.0 | 3400 | 3401 | 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. | 3401 | 3406 | - version: v25.4.0 | 3402 | 3407 | 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. | 3404 | 3409 | - version: | 3405 | 3410 | - v24.0.0 | 3406 | 3411 | - v22.17.0 | @@ -3410,7 +3415,9 @@ changes: | 3410 | 3415 |
| 3411 | 3416 | * `streamDuplex` {stream.Duplex} | 3412 | 3417 | * `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.) | 3414 | 3421 | * Returns: {Object} | 3415 | 3422 | * `readable` {ReadableStream} | 3416 | 3423 | * `writable` {WritableStream} | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js +10-4Lines changed: 10 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -624,7 +624,7 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj | 624 | 624 |
| 625 | 625 | /** | 626 | 626 | * @param {Duplex} duplex | 627 | | - * @param {{ type?: 'bytes' }} [options] | | 627 | + * @param {{ readableType?: 'bytes' }} [options] | 628 | 628 | * @returns {ReadableWritablePair} | 629 | 629 | */ | 630 | 630 | function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) { | @@ -641,9 +641,15 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) { | 641 | 641 |
| 642 | 642 | validateObject(options, 'options'); | 643 | 643 |
| | 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 | + | 644 | 650 | if (isDestroyed(duplex)) { | 645 | 651 | const writable = new WritableStream(); | 646 | | - const readable = new ReadableStream({ type: options.type }); | | 652 | + const readable = new ReadableStream({ type: readableOptions.type }); | 647 | 653 | writable.close(); | 648 | 654 | readable.cancel(); | 649 | 655 | return { readable, writable }; | @@ -659,8 +665,8 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) { | 659 | 665 |
| 660 | 666 | const readable = | 661 | 667 | isReadable(duplex) ? | 662 | | - newReadableStreamFromStreamReadable(duplex, options) : | 663 | | - new ReadableStream({ type: options.type }); | | 668 | + newReadableStreamFromStreamReadable(duplex, readableOptions) : | | 669 | + new ReadableStream({ type: readableOptions.type }); | 664 | 670 |
| 665 | 671 | if (!isReadable(duplex)) | 666 | 672 | readable.cancel(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-duplex.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,10 +147,14 @@ process.on('exit', () => { | 147 | 147 | }) | 148 | 148 | }); | 149 | 149 |
| 150 | | - const { writable, readable } = Duplex.toWeb(duplex, { type: 'bytes' }); | | 150 | + const { writable, readable } = Duplex.toWeb(duplex, { readableType: 'bytes' }); | 151 | 151 | writable.getWriter().write(dataToWrite); | 152 | 152 | const data = new Uint8Array(dataToRead.length); | 153 | 153 | readable.getReader({ mode: 'byob' }).read(data).then(common.mustCall((result) => { | 154 | 154 | assert.deepStrictEqual(Buffer.from(result.value), dataToRead); | 155 | 155 | })); | | 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' }); | 156 | 160 | } |
|