Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
LICENSE | D | 12-May-2024 | 1.1 KiB | 21 | 17 | |
README.md | D | 12-May-2024 | 1.5 KiB | 53 | 37 | |
index.js | D | 12-May-2024 | 2.4 KiB | 88 | 69 | |
package.json | D | 12-May-2024 | 1.8 KiB | 73 | 72 |
README.md
1# end-of-stream 2 3A node module that calls a callback when a readable/writable/duplex stream has completed or failed. 4 5 npm install end-of-stream 6 7## Usage 8 9Simply pass a stream and a callback to the `eos`. 10Both legacy streams, streams2 and stream3 are supported. 11 12``` js 13var eos = require('end-of-stream'); 14 15eos(readableStream, function(err) { 16 // this will be set to the stream instance 17 if (err) return console.log('stream had an error or closed early'); 18 console.log('stream has ended', this === readableStream); 19}); 20 21eos(writableStream, function(err) { 22 if (err) return console.log('stream had an error or closed early'); 23 console.log('stream has finished', this === writableStream); 24}); 25 26eos(duplexStream, function(err) { 27 if (err) return console.log('stream had an error or closed early'); 28 console.log('stream has ended and finished', this === duplexStream); 29}); 30 31eos(duplexStream, {readable:false}, function(err) { 32 if (err) return console.log('stream had an error or closed early'); 33 console.log('stream has finished but might still be readable'); 34}); 35 36eos(duplexStream, {writable:false}, function(err) { 37 if (err) return console.log('stream had an error or closed early'); 38 console.log('stream has ended but might still be writable'); 39}); 40 41eos(readableStream, {error:false}, function(err) { 42 // do not treat emit('error', err) as a end-of-stream 43}); 44``` 45 46## License 47 48MIT 49 50## Related 51 52`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one. 53