I am writing my own HTTP module if I need to respond with a binary file, for example ..jpg,
I load the file using: body = fs.createReadStream(pathOfFile) .
When I generate a response, I use: body.pipe(socket);
But as an HTTP response, I wanted to add a Content-Length header.
I could not find an easy way to do this, fs.stat does not give the result immediately, but right after I called the channel.
In any case, know what to send to the Content-Length header.
Thanks.
source share