I have another solution for recording in two streams at the same time, of course, the time for recording will be two times adding, but I use it to respond to the download request, where I want to save a copy of the downloaded file on my server (in fact, I use the backup S3, so I cache the most used files locally to avoid multiple file transfers)
class TwoOutputStreams { constructor(streamOne, streamTwo) { this.streamOne = streamOne this.streamTwo = streamTwo } setHeader(header, value) { if (this.streamOne.setHeader) this.streamOne.setHeader(header, value) if (this.streamTwo.setHeader) this.streamTwo.setHeader(header, value) } write(chunk) { this.streamOne.write(chunk) this.streamTwo.write(chunk) } end() { this.streamOne.end() this.streamTwo.end() } }
Then you can use this as a regular OutputStream
const twoStreamsOut = new TwoOutputStreams(fileOut, responseStream)
and pass it to your method as if it were an answer or an OutputStream file
Zied Hamdi Nov 08 '17 at 17:50 2017-11-08 17:50
source share