Promisify Await WriteStream ReadStream Streams
See original GitHub issueHi @jprichardson @RyanZim I want to await the end of a stream. Are there any plans to add that? Would you be interested in a PR? If yes, should the api be to return the same old e.g. WriteStream
with an added .promise()
that can be awaited?
Edit - maybe the promises should be the names of the events? E.g. await fse.createWriteStream(path).end()
?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
How to use ES8 async/await with streams? - Stack Overflow
async / await only works with promises, not with streams. There are ideas to make an extra stream-like data type that would get...
Read more >Understanding Streams in Node.js | NodeDev
createWriteStream () lets us write data to a file using streams. Readable: streams from which data can be read. For example: fs.
Read more >Easier Node.js streams via async iteration - 2ality
Asynchronous iteration is a protocol for retrieving the contents of a data container asynchronously (meaning the current “task” may be paused ...
Read more >Wrap your streams with promises for fun and profit
Now streamToFile immediately returns a promise object that we can pass around, await in some other async function, or chain .then and .catch ......
Read more >Stream | Node.js v19.3.0 Documentation
Consuming readable streams with async iterators; Creating readable streams with ... createWriteStream('file.txt'); // All the data from readable goes into ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @RyanZim,
The nodejs s3 api only gave me a stream. I wanted to download a file to disk so I can process it in ffmpeg. So I needed to know when the file was done downloading.
Here’s what I ended up with:
I didn’t do the due diligence to figure out the difference between
finish
andend
but it worked so I moved on.Just to add another data point: I was also looking for this functionality.
I have a
stream.Readable
from a http response and want to write it to a file. I would think in a Node.js environment it is common to work with streams, so having native support in this library would be useful. (I would be worried that not everybody will write their ownstreamPromise
function like above, but rather read the whole stream into a Buffer to then be able to use the standardfs-extra
functions…)