Skip to content
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

Async iterator support? #74

Open
josephrocca opened this issue Dec 26, 2018 · 3 comments
Open

Async iterator support? #74

josephrocca opened this issue Dec 26, 2018 · 3 comments

Comments

@josephrocca
Copy link

Would be cool if this lib were compatible with the new async iteration stuff! So we can, for example, do this:

const chunksAsync = stream.pipe(lzma.createDecompressor());
for await(const chunk of chunksAsync) {
  ...
}

Is there any reason why this lib is not using node's built-in streams? Because that would prevent the need for future updates of this sort.

@addaleax
Copy link
Owner

Is there any reason why this lib is not using node's built-in streams?

Erm, at least at the time when this library was created, readable-stream was the go-to thing.

It’s probably fine to changes this at this point – I assume that that’s a breaking change, though. Is there any point in doing dependency injection, i.e. letting users choose between built-in vs readable-stream?

@josephrocca
Copy link
Author

josephrocca commented Jan 3, 2019

Sounds like you were probably right not to use the built-in stuff: https://www.npmjs.com/package/readable-stream

If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use readable-stream only and avoid the "stream" module in Node-core, for background see this blogpost.

I haven't read that blog post yet, but they make the in-built streams sound scary, so maybe just wait for readable-stream to implement async iterator stuff, and then upgrade that package? ¯_(ツ)_/¯

@rgrannell1
Copy link

rgrannell1 commented Jul 25, 2020

as a workaround, I used

import { PassThrough }  from 'stream'

const pass = new PassThrough()
const readStream = fs.createReadStream(fpath).pipe(pass)

for await (const buffer of readStream) {

}

as a workaround for this issue. This appears to work, until readable-stream supports async-iterators natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants