Reputation: 1914
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.
Upvotes: 4
Views: 6816
Reputation: 20315
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.
Upvotes: 9