Some related links
Basically, there're two functions that need implementing:
-
Consume a readable stream as an async iterator.
This function is called when input files are consumed as readable streams and we expect to use async generators to manipulate chunks (regulating them to equally sized chunks, applying hash algorithm on them) of the file streams.
This feature is already merged in the web streams spec, but not yet implemented by mainstream browsers:
So, a polyfill is in need for now. There're already some good implementations:
-
MattiasBuelens/web-streams-polyfill
Written by the spec contributor Mattias Buelens, this repo is considered canonical but it polyfills all readable stream related APIs which seems not appropriate to be used only as a polyfill of async iteration.
-
ThaUnknown/fast-readable-async-iterator
Written by Cas who pointed out the performance issue in using web streams in my repo and implemented async iterations for webtorrent/create-torrent. His implementation uses one-value ahead cache, for performance reasons, I think, and properly cancels the stream when the iteration is returned or thrown, which is good. But I think there're still some problems:
- The readable stream won't be released when the iteration is normally exited (i.e., loop exits without calls of
return or throw)
- It does not support
stream.values({ preventCancel: true })
- A lack of Typescript types
There're some other existing snippets that have similar or more significant problems, including this one by ji...@warting.se or this one by dy.
I intend to implement a spec-compliant polyfill in typescript. Performance is my second consideration as I think browser support will eventually supersede this polyfill soon enough (hopefully). This polyfill I'm working on is Sec-ant/readable-stream. It now passes all the tests that are copied from wpt.
-
Construct a readable stream from an async iterator or iterator.
This function is called when we want to collect the results and produce them as a ReadableStream, which can be later consumed as a Response or be piped to a FileSystemWritableFileStream.
ReadableStream.from is the proposed API yet not merged in the spec:
Reference implementations:
I implemented a fromIterable function in Sec-ant/readable-stream to fill in the absence of ReadableStream.from. It now passes all the tests that are copied from wpt.
Other works left including refactoring transformers to async generators are already done in another branch of this repo. But they still need testing as I also refactored many other places.
Some related links
readable-streamtostreamxwebtorrent/webtorrent#1971Basically, there're two functions that need implementing:
Consume a readable stream as an async iterator.
This function is called when input files are consumed as readable streams and we expect to use async generators to manipulate chunks (regulating them to equally sized chunks, applying hash algorithm on them) of the file streams.
This feature is already merged in the web streams spec, but not yet implemented by mainstream browsers:
So, a polyfill is in need for now. There're already some good implementations:
MattiasBuelens/web-streams-polyfill
Written by the spec contributor Mattias Buelens, this repo is considered canonical but it polyfills all readable stream related APIs which seems not appropriate to be used only as a polyfill of async iteration.
ThaUnknown/fast-readable-async-iterator
Written by Cas who pointed out the performance issue in using web streams in my repo and implemented async iterations for webtorrent/create-torrent. His implementation uses one-value ahead cache, for performance reasons, I think, and properly cancels the stream when the iteration is returned or thrown, which is good. But I think there're still some problems:
returnorthrow)stream.values({ preventCancel: true })There're some other existing snippets that have similar or more significant problems, including this one by ji...@warting.se or this one by dy.
I intend to implement a spec-compliant polyfill in typescript. Performance is my second consideration as I think browser support will eventually supersede this polyfill soon enough (hopefully). This polyfill I'm working on is Sec-ant/readable-stream. It now passes all the tests that are copied from wpt.
Construct a readable stream from an async iterator or iterator.
This function is called when we want to collect the results and produce them as a
ReadableStream, which can be later consumed as aResponseor be piped to aFileSystemWritableFileStream.ReadableStream.fromis the proposed API yet not merged in the spec:Reference implementations:
I implemented a
fromIterablefunction in Sec-ant/readable-stream to fill in the absence ofReadableStream.from. It now passes all the tests that are copied from wpt.Other works left including refactoring transformers to async generators are already done in another branch of this repo. But they still need testing as I also refactored many other places.