How to create a temporary recording stream?

I have a file stream that I want to pass in the transformRead () method that accepts readStream and writeStream, but I don't know how to create a temporary write stream ... do I need to use a file? I just need some kind of pipe () from rs to ws, then ws gzipped and sent back.

// Get file stream var rs = store.getReadStream(fileId); var ws = ?????; // Execute transformation store.transformRead(rs, ws, fileId); var accept = req.headers['accept-encoding'] || ''; // Compress data if supported by the client if (accept.match(/\bdeflate\b/)) { res.writeHead(200, { 'Content-Encoding': 'deflate', 'Content-Type': file.type }); ws.pipe(zlib.createDeflate()).pipe(res); } else if (accept.match(/\bgzip\b/)) { res.writeHead(200, { 'Content-Encoding': 'gzip', 'Content-Type': file.type }); ws.pipe(zlib.createGzip()).pipe(res); } else { res.writeHead(200, {}); ws.pipe(res); } 
+4
source share
2 answers

Use through2 to easily create a conversion stream (read / write)

+2
source

Finally, someone told me about using stream.PassThrough();

Thus, the simplest and β€œnative” solution is:

 var ws = new stream.PassThrough(); 
0
source

All Articles