3

Is it possible reopen a closed stream after calling stream.end()?

My requirement is to use streams to write in chunks and the whole process is called inside a scheduler, so once the stream is closed and the next time scheduler is called the said error is emitted which is really undesirable.

And also I don't want to create a new stream every time the scheduler runs.

Node.js Stream's documentation says

Calling the stream.write() method after calling stream.end() will raise an error.

PrivateOmega
  • 2,509
  • 1
  • 17
  • 27
  • 1
    If you still have things to write to the stream, why do you close it? – jonrsharpe Apr 12 '19 at 06:55
  • @jonrsharpe I am closing it for that iteration, when scheduler runs again I need it to be open again. How else could I listen to finish event of stream? – PrivateOmega Apr 12 '19 at 07:04

1 Answers1

3

Unfortunately, no, this isn't possible. Once a stream is closed, it is closed.

Golo Roden
  • 140,679
  • 96
  • 298
  • 425