node.jsnode.js-stream

How do I test if a stream has ended?


I have a stream that may or may not have already ended. If it has ended, I don't want to sit there forever waiting for the end event. How do I check?


Solution

  • As of node 12.9.0, readable streams have a readableEnded property you can check – see readable.readableEnded in the Stream documentation.

    (Writable streams have a corresponding property)