How can I provide an input stream to send node.js / express' or get its original output stream?

I provide the route in my express application, which provides the contents of the cloud file as a download. I have access to the input stream of a cloud file, and I would like to transfer it directly to the response output stream. However, I am using express, which does not seem to support the input stream.

I was hoping I could do this:

res.send (cloudInputStream); 

but it does not work. Express' sends a body or buffer, but apparently not an input stream.

In this case, I would like to set the headers using res.setHeader (), then access the raw output stream, and then:

cloudInputStream.pipe (responseOutputStream);

Is it possible?

Alternatively, I could turn the input stream into a buffer and provide this buffer for sending. However, it reads the entire contents of the cloud file in memory at a time, which I would like to avoid.

Any thoughts?

+4
source share
2 answers

All you have to do is cloudInputStream.pipe(res) after setting the headers.

+9
source

You can do anything node. Use pipe for streams and res.set for header fields or res.sendfile.

+4
source

All Articles