Skip to content

Streams: support ReadableStream.from() #48389

Description

@MattiasBuelens

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

Activity

  1. MattiasBuelens commented on Jun 8, 2023

    @MattiasBuelens
    ContributorAuthor

    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).

  2. added
    web streamsIssues and PRs related to the Web Streams API.
    feature requestIssues requesting new Node.js features.
    on Jun 8, 2023
  3. debadree25 commented on Jun 8, 2023

    @debadree25
    Contributor

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

  4. moved this from Awaiting Triage to Done in Node.js feature requestson Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.web streamsIssues and PRs related to the Web Streams API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions