Reputation: 376
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?
Upvotes: 1
Views: 787
Reputation: 376
This worked for me:
let size = 0
compressedStream.on('data', (chunk) => {
size = size + chunk.length
})
compressedStream.on('end', () => {
console.log(size)
})
Upvotes: 0
Reputation: 435
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);
});
Upvotes: 1