I need to know the content-length of a readable stream. How can I do it?
I know about fs.stat
but I am developing an API that knowing the content-length from a readable stream would be much simpler.
the idea behind the stream is that you start working on data before the source finishes. thus, you don't know the content-length
.
if the underlying source is an HTTP object, then you could check stream.headers['content-length']
, but even that is not ultimately reliable as the client or the server could have lied.
in short, you can't. personally, i'd rather just store it on disk temporarily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With