Search code examples
node.jsnode-streams

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.


Solution

  • Been googling the same thing, you can just add

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