Skip to content

Commit 03df76c

Browse files
gabrielschulhofaduh95
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 <luigipinca@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
1 parent 8dc39e5 commit 03df76c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

doc/api/webstreams.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,41 @@ async function* asyncIterableGenerator() {
436436
})();
437437
```
438438

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

441476
<!-- YAML

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy