Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent end messages from closing Nodejs streams?

In a Node server I have a series of streams piped together. Say, for example:

streamA.pipe(streamB).pipe(streamC)

Eventually streamA completes and at that point I want to switch the downstreams to another source:

streamD.pipe(streamB).pipe(streamC)

But when I try to do this I get the following error:

Error: write after end

How can I prevent streamA from closing my downstreams? Or how can I open my downstreams back up to switch them over to streamD?

Also, my use case requires that I wait until streamA end. I can't switch the streams prematurely.

like image 261
SuperDeclarative Avatar asked Nov 26 '25 00:11

SuperDeclarative


1 Answers

Been googling the same thing, you can just add

streamA.pipe(streamB, {end: false}).pipe(streamC, {end: false})

like image 185
Thomas Nairn Avatar answered Nov 27 '25 14:11

Thomas Nairn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!