dan gibson dan gibson - 3 months ago 14
Node.js Question

What is the difference between stream.end and stream.destroySoon for files in Node.js?

I'm writing to a file (a writable steam) and I need to close the file once I'm done. I'm not sure of the difference between these two functions or if I need to call them both. Here's what the documentation says:


Terminates the stream with EOF or FIN. This call will allow queued write data to be sent before closing the stream.


After the write queue is drained, close the file descriptor.
can still destroy straight away, as long as there is no data left in the queue for writes.


There is no difference.

From fs.js in the node source:

// There is no shutdown() for files.
WriteStream.prototype.destroySoon = WriteStream.prototype.end;