1

I have a function call uploadStream(compressedStream) in my code where I am passing compressedStream as a parameter to the function but before that I need to determine the length of the compressedStream. Does anyone know how can I do that in NodeJS?

Mayank Patel
  • 346
  • 3
  • 18
  • Does this answer your question? [node.js: determine length of stream before it is piped to final destination](https://stackoverflow.com/questions/54008318/node-js-determine-length-of-stream-before-it-is-piped-to-final-destination) – eol Aug 03 '21 at 07:28

2 Answers2

1

you can get length by getting stream chunks length on the "data" event

compressedStream.on('data', (chunk) => {
   console.log('Got %d characters of string data:', chunk.length);
});
MHassan
  • 415
  • 4
  • 9
0

This worked for me:

            let size = 0
            compressedStream.on('data', (chunk) => {
              size = size + chunk.length
            })
            compressedStream.on('end', () => {
              console.log(size)
            })
Mayank Patel
  • 346
  • 3
  • 18