You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 })
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:
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.
The text was updated successfully, but these errors were encountered:
@ThaUnknown Again, thanks for your tips! Yeah, I simply gathered all the related discussions/implementations as a reminder. I went through some of the links and realized some of them might not be what I need but nevertheless steps guiding me to the right direction😄. I really appreciate that many of your repos have offered me much help! I'm currently using a simple implementation written by myself: Sec-ant/readable-stream.
Some related links
readable-stream
tostreamx
webtorrent/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:
return
orthrow
)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 aResponse
or be piped to aFileSystemWritableFileStream
.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 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.
The text was updated successfully, but these errors were encountered: