![]() |
VOOZH | about |
The stream.finished() method is utilized to receive an alert if a stream is not writable or readable anymore or if it had experienced an error or a close event that is immature.
Syntax:
stream.finished(stream, options, callback)
Parameters: This method accepts three parameters as mentioned above and described below:
Return Value: It returns a cleanup function that detaches all the registered listeners.
The below examples illustrate the use of the stream.finished() method in Node.js:
Example 1:
Output:
Promise { <pending> }
Readable is being consumed
Example 2:
Output: Here, an error occurs while writing the file name so an error is returned in the output.
Promise { <pending> }
{ [Error: ENOENT: no such file or directory, open 'input.text']
errno: -2, code: 'ENOENT', syscall: 'open', path: 'input.text' }
Reference: https://nodejs.org/api/stream.html#stream_stream_finished_stream_options_callback