-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Support ReadableStream.from()
#3700
Comments
This should be easy for us to add. The implementation of it is just copy pasting what they do into our readable stream files. We use TS instead of JS is the main difference i think. |
Hey @paperdave is it cool if I work on this? |
go for it. with the builtin functions right now you have to run |
Likely fixed by bun 0.8 - @MattiasBuelens is it working for you now? |
@birkskyum Unfortunately no, bun 0.8 doesn't support this yet. $ bun --version
0.8.1
$ cat index.ts
let rs = ReadableStream.from(["a", "b"]);
for await (const x of rs) {
console.log(x);
}
console.log("done!");
$ bun run index.ts
1 | let rs = ReadableStream.from(["a", "b"]);
^
TypeError: ReadableStream.from is not a function. (In 'ReadableStream.from(["a", "b"])', 'ReadableStream.from' is undefined)
at index.ts:1:9 |
Okay - the bun docs state that ReadableStream is fully implemented. Doesn't seem to be the case |
Hence why I opened this issue. 😅 Bun "fully supports" the Streams standard, but not yet the latest version of the standard. Streams is a living standard, which means new features are still being added. Browsers and runtimes need some time to catch up and implement the latest changes. That's totally fine, and expected. For browsers and Node.js, you can track their progress on https://wpt.fyi/. For example, at the time of writing, Firefox Nightly and Node.js Nightly already support |
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 aReadableStream
. Once Bun supports this method, creating aReadableStream
from an array would become a one-liner.Specification: https://streams.spec.whatwg.org/#rs-from
Spec change: whatwg/streams#1083
WPT tests: web-platform-tests/wpt#27009
Deno and Node.js also recently implemented this new method, see denoland/deno#19446 and nodejs/node#48395.
Since Bun is powered by JavaScriptCore, you may also want to look into their pull request: WebKit/WebKit#12454
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: