You can't pipe a readable stream to another readable stream. The flow is:
readable.pipe(writable);
A writable, is this case, could be:
So, if you're trying to read multiple files and pipe them to a writable stream, you have to pipe each one to the writable stream and and pass end: false
when doing it, because by default, a readable stream ends the writable stream when there's no more data to be read. Here's an example:
var ws = fs.createWriteStream('output.pdf');
fs.createReadStream('pdf-sample1.pdf').pipe(ws, { end: false });
fs.createReadStream('pdf-sample2.pdf').pipe(ws, { end: false });
fs.createReadStream('pdf-sample3.pdf').pipe(ws);
Of course, this is not the best way to do it, you could implement a function to wrap this logic in a more generic way, maybe with a loop or a recursive solution.
An even simpler solution would be to use a module that already solved this problem, like this one here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…