| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b92ff7b commit 1ef9c9a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -432,6 +432,41 @@ async function* asyncIterableGenerator() { | |||
| 432 | 432 | })(); | |
| 433 | 433 | ``` | |
| 434 | 434 | ||
| 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 | + | ||
| 435 | 470 | ### Class: `ReadableStreamDefaultReader` | |
| 436 | 471 | ||
| 437 | 472 | <!-- YAML | |
| Back | FazBrowse Home | New Git URL |
0 commit comments