source: trip-planner-front/node_modules/end-of-stream/README.md@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[6a3a178]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[![Build status](https://travis-ci.org/mafintosh/end-of-stream.svg?branch=master)](https://travis-ci.org/mafintosh/end-of-stream)
8
9## Usage
10
11Simply pass a stream and a callback to the `eos`.
12Both legacy streams, streams2 and stream3 are supported.
13
14``` js
15var eos = require('end-of-stream');
16
17eos(readableStream, function(err) {
18 // this will be set to the stream instance
19 if (err) return console.log('stream had an error or closed early');
20 console.log('stream has ended', this === readableStream);
21});
22
23eos(writableStream, function(err) {
24 if (err) return console.log('stream had an error or closed early');
25 console.log('stream has finished', this === writableStream);
26});
27
28eos(duplexStream, function(err) {
29 if (err) return console.log('stream had an error or closed early');
30 console.log('stream has ended and finished', this === duplexStream);
31});
32
33eos(duplexStream, {readable:false}, function(err) {
34 if (err) return console.log('stream had an error or closed early');
35 console.log('stream has finished but might still be readable');
36});
37
38eos(duplexStream, {writable:false}, function(err) {
39 if (err) return console.log('stream had an error or closed early');
40 console.log('stream has ended but might still be writable');
41});
42
43eos(readableStream, {error:false}, function(err) {
44 // do not treat emit('error', err) as a end-of-stream
45});
46```
47
48## License
49
50MIT
51
52## Related
53
54`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.
Note: See TracBrowser for help on using the repository browser.