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 03df76c

Browse filesBrowse 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
Copy full SHA for 03df76c

File tree

Expand file treeCollapse file tree

1 file changed

+35
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+35
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/webstreams.md‎

Copy file name to clipboardExpand all lines: doc/api/webstreams.md
+35Lines changed: 35 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.