oven-sh/bun

Support `ReadableStream.from()`

Chiusa

#3700 aperta il 20 lug 2023

 (9 commenti) (11 reazioni) (0 assegnatari)Rust (4486 fork)batch import
enhancementgood first issueweb-api

Metriche repository

Star
 (90.348 stelle)
Metriche merge PR
 (Merge medio 1g 17h) (357 PR mergiate in 30 g)

Descrizione

What is the problem this feature would solve?

Creating a ReadableStream from an array (or any other iterable) requires a lot of boilerplate, as can be seen in these tests and this example.

What is the feature you are proposing to solve the problem?

The Streams standard now has a new utility method ReadableStream.from(asyncIterable), which adapts any sync or async iterable into a ReadableStream. Once Bun supports this method, creating a ReadableStream from an array would become a one-liner.

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

Deno and Node.js also recently implemented this new method, see https://github.com/denoland/deno/pull/19446 and https://github.com/nodejs/node/pull/48395.

Since Bun is powered by JavaScriptCore, you may also want to look into their pull request: https://github.com/WebKit/WebKit/pull/12454

What alternatives have you considered?

No response

Guida contributor