I find the Node.js docs to be unclear.
It appears to me that the 'close' event will fire once the Readable stream has finished sending its data, regardless if it has been completely consumed or not.
The 'end' event seems to only be fired if all of the data has been consumed from the Readable stream.
What is the actual difference? When will each event be fired?
From the docs
The 'close' event is emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed. The event indicates that no more events will be emitted, and no further computation will occur.
As it says, it will be fired if one of its resources is closed, regardless of the data emitted. You might find it useful to clean up if it closed before all the data was sent or something similar.
The 'end' event is emitted when there is no more data to be consumed from the stream.
In this case, the end will fire only when all the data of the stream has been consumed.
They are quite different, and they are both useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With