简体   繁体   中英

How to find the content-length of a readable stream in nodejs?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM