Node.js streams triggers both end
and finish
events. What's the difference between both?
A buffer is a temporary memory that a stream takes to hold some data until it is consumed. In a stream, the buffer size is decided by the highWatermark property on the stream instance which is a number denoting the size of the buffer in bytes. A buffer memory in Node by default works on String and Buffer .
Chaining the Streams Chaining is a mechanism to connect the output of one stream to another stream and create a chain of multiple stream operations. It is normally used with piping operations. Now we'll use piping and chaining to first compress a file and then decompress the same.
Introduction. A stream is an abstraction of data in programming. The Node. js Stream API has been around for a long time and is used as a uniform API for reading and writing asynchronous data.
end
and finish
are the same event BUT on different types of Streams.
stream.Readable
fires ONLY end
and NEVER finish
stream.Writable
fires ONLY finish
and NEVER end
Source: https://nodejs.org/dist/latest-v5.x/docs/api/stream.html
Why the different naming of the same event?
The only reason I could think of is because of duplex streams (stream.Duplex
), which implement both stream.Readable
and stream.Writable
interfaces (https://nodejs.org/dist/latest-v5.x/docs/api/stream.html#stream_class_stream_duplex) are readable and writable stream at the same time. To differentiate between end of reading and end of writing on the stream you must have a different event fired. SO, for Duplex streams end
is end of reading and finish
is end of writing.
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