Node.js - write two readable streams to the same writeable stream

I am wondering how node.js oprates is if you are connecting two different read streams to the same destination at the same time. For instance:

var a = fs.createReadStream('a')
var b = fs.createReadStream('b')
var c = fs.createWriteStream('c')
a.pipe(c, {end:false})
b.pipe(c, {end:false})

Does this write a to c and then b to c? Or did it ruin everything?

+3
source share
1 answer

You want to add a second read to the eventlistener for the first read to complete.

var a = fs.createReadStream('a');
var b = fs.createReadStream('b');
var c = fs.createWriteStream('c');
a.pipe(c, {end:false});
a.on('end', function() {
  b.pipe(c)
}
+1
source

All Articles