B T
B T

Reputation: 60875

node.js - writing two readable streams into the same writable stream

I'm wondering how node.js oprates if you pipe two different read streams into the same destination at the same time. For example:

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 into c, then b into c? Or does it mess everything up?

Upvotes: 5

Views: 2624

Answers (1)

Jordan Honeycutt
Jordan Honeycutt

Reputation: 338

You want to add the second read into an eventlistener for the first read to finish.

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)
}

Upvotes: 4

Related Questions