3 A node module that calls a callback when a readable/writable/duplex stream has completed or failed.
5 npm install end-of-stream
9 Simply pass a stream and a callback to the `eos`.
10 Both legacy streams and streams2 are supported.
13 var eos = require('end-of-stream');
15 eos(readableStream, function(err) {
16 if (err) return console.log('stream had an error or closed early');
17 console.log('stream has ended');
20 eos(writableStream, function(err) {
21 if (err) return console.log('stream had an error or closed early');
22 console.log('stream has finished');
25 eos(duplexStream, function(err) {
26 if (err) return console.log('stream had an error or closed early');
27 console.log('stream has ended and finished');
30 eos(duplexStream, {readable:false}, function(err) {
31 if (err) return console.log('stream had an error or closed early');
32 console.log('stream has ended but might still be writable');
35 eos(duplexStream, {writable:false}, function(err) {
36 if (err) return console.log('stream had an error or closed early');
37 console.log('stream has ended but might still be readable');
40 eos(readableStream, {error:false}, function(err) {
41 // do not treat emit('error', err) as a end-of-stream