Skip to content
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

Streams: support ReadableStream.from() #48389

Closed
MattiasBuelens opened this issue Jun 8, 2023 · 2 comments · Fixed by #48395
Closed

Streams: support ReadableStream.from() #48389

MattiasBuelens opened this issue Jun 8, 2023 · 2 comments · Fixed by #48395
Labels
feature request Issues that request new features to be added to Node.js. web streams

Comments

@MattiasBuelens
Copy link
Contributor

The Streams standard has been updated with a new utility method ReadableStream.from(asyncIterable), which adapts any sync or async iterable into a ReadableStream.

Specification: https://streams.spec.whatwg.org/#rs-from
Spec change: whatwg/streams#1083
WPT tests: web-platform-tests/wpt#27009

@MattiasBuelens
Copy link
Contributor Author

This is very similar to Node's Readable.from(iterable), except for Web Streams. And because both Readable and ReadableStream are async iterables and have a static from() method, there's a nice duality for converting them:

import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';

const nodeReadable = new Readable({ /* ... */ });
const webReadableStreamFromNodeReadable = ReadableStream.from(nodeReadable);

const webReadableStream = new ReadableStream({ /* ... */ });
const nodeReadableFromWebReadableStream = Readable.from(webReadableStream);

Also, Readable.toWeb(nodeReadable) will be equivalent to ReadableStream.from(nodeReadable) (although the former can be optimized specifically for Node streams, whereas the latter is more general).

@debadree25
Copy link
Member

Hey! will give this a try hoping to have a PR ready soon!

debadree25 added a commit to debadree25/node that referenced this issue Jun 8, 2023
debadree25 added a commit to debadree25/node that referenced this issue Jun 8, 2023
debadree25 added a commit to debadree25/node that referenced this issue Jun 24, 2023
debadree25 added a commit to debadree25/node that referenced this issue Jul 13, 2023
debadree25 added a commit to debadree25/node that referenced this issue Jul 13, 2023
nodejs-github-bot pushed a commit that referenced this issue Jul 18, 2023
Fixes: #48389
PR-URL: #48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
pluris pushed a commit to pluris/node that referenced this issue Aug 6, 2023
Fixes: nodejs#48389
PR-URL: nodejs#48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
pluris pushed a commit to pluris/node that referenced this issue Aug 7, 2023
Fixes: nodejs#48389
PR-URL: nodejs#48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48389
PR-URL: nodejs#48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48389
PR-URL: nodejs#48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48389
PR-URL: nodejs#48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
RafaelGSS pushed a commit that referenced this issue Aug 15, 2023
Fixes: #48389
PR-URL: #48395
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@RedYetiDev RedYetiDev moved this from Awaiting Triage to Done in Node.js feature requests Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. web streams
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants