Is it possible to listen to a Node.js ReadableStream so I can, for instance, show a progress bar in the console as a file is being read?
In my particular case, another library is taking my ReadableStream: fs.createReadStream(filePath)
. In the same vein, I want to watch this stream to see how much data has been moved through this library.
I was doing stream.on('data', callback)
, but realized it was actually reading the stream. I'd rather listen for changes instead. I couldn't figure out how pipe
would help me or any other methods.
you could use the progress-stream package to do exactly what you asked for. if you are intrested in how you can implement this your self - check out the github page for the project and also look at these resources.