-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
doc: add example for piping ReadableStream #56415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -436,6 +436,39 @@ async function* asyncIterableGenerator() { | |||||
| })(); | ||||||
| ``` | ||||||
|
|
||||||
| To pipe the resulting {ReadableStream} into a {WritableStream} the {Iterable} | ||||||
| should yield a sequence of {Buffer}, {TypedArray}, or {DataView} objects. | ||||||
|
|
||||||
| ```mjs | ||||||
| import { ReadableStream } from 'node:stream/web'; | ||||||
| import { Buffer } from 'node:buffer'; | ||||||
|
|
||||||
| async function* asyncIterableGenerator() { | ||||||
| yield Buffer.from('a'); | ||||||
| yield Buffer.from('b'); | ||||||
| yield Buffer.from('c'); | ||||||
| } | ||||||
|
|
||||||
| const stream = ReadableStream.from(asyncIterableGenerator()); | ||||||
|
|
||||||
| stream.pipeTo(createWritableStreamSomehow()); | ||||||
| ``` | ||||||
|
|
||||||
| ```cjs | ||||||
| const { ReadableStream } = require('node:stream/web'); | ||||||
| const { Buffer } = require('node:buffer'); | ||||||
|
|
||||||
| async function* asyncIterableGenerator() { | ||||||
| yield Buffer.from('a'); | ||||||
| yield Buffer.from('b'); | ||||||
| yield Buffer.from('c'); | ||||||
| } | ||||||
|
|
||||||
| const stream = ReadableStream.from(asyncIterableGenerator()); | ||||||
|
|
||||||
| stream.pipeTo(createWritableStreamSomehow()); | ||||||
|
||||||
| stream.pipeTo(createWritableStreamSomehow()); | |
| stream.pipeTo(createWritableStreamSomehow()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell I put this in an async IIFE and awaited the promise.
Uh oh!
There was an error while loading. Please reload this page.