dan gibson dan gibson - 2 months ago 8
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:

stream.end()


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

stream.destroySoon()


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

Answer

There is no difference.

From fs.js in the node source:

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