Skip to content

Commit 1ef9c9a

Browse files
gabrielschulhofmarco-ippolito
authored andcommitted
doc: add example for piping ReadableStream
When piping a `ReadableStream` created from an `Iterable` into a `WritableStream`, the sequence of objects in the `Iterable` must consist of either `Buffer`s, `TypedArray`s, or `DataView`s. Re: #56297 PR-URL: #56415 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Ulises Gascón <[email protected]>
1 parent b92ff7b commit 1ef9c9a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

doc/api/webstreams.md

+35
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,41 @@ async function* asyncIterableGenerator() {
432432
})();
433433
```
434434

435+
To pipe the resulting {ReadableStream} into a {WritableStream} the {Iterable}
436+
should yield a sequence of {Buffer}, {TypedArray}, or {DataView} objects.
437+
438+
```mjs
439+
import { ReadableStream } from 'node:stream/web';
440+
import { Buffer } from 'node:buffer';
441+
442+
async function* asyncIterableGenerator() {
443+
yield Buffer.from('a');
444+
yield Buffer.from('b');
445+
yield Buffer.from('c');
446+
}
447+
448+
const stream = ReadableStream.from(asyncIterableGenerator());
449+
450+
await stream.pipeTo(createWritableStreamSomehow());
451+
```
452+
453+
```cjs
454+
const { ReadableStream } = require('node:stream/web');
455+
const { Buffer } = require('node:buffer');
456+
457+
async function* asyncIterableGenerator() {
458+
yield Buffer.from('a');
459+
yield Buffer.from('b');
460+
yield Buffer.from('c');
461+
}
462+
463+
const stream = ReadableStream.from(asyncIterableGenerator());
464+
465+
(async () => {
466+
await stream.pipeTo(createWritableStreamSomehow());
467+
})();
468+
```
469+
435470
### Class: `ReadableStreamDefaultReader`
436471

437472
<!-- YAML

0 commit comments

Comments
 (0)