Initial commit
[yaffs-website] / node_modules / end-of-stream / README.md
1 # end-of-stream
2
3 A 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
9 Simply pass a stream and a callback to the `eos`.
10 Both legacy streams and streams2 are supported.
11
12 ``` js
13 var eos = require('end-of-stream');
14
15 eos(readableStream, function(err) {
16         if (err) return console.log('stream had an error or closed early');
17         console.log('stream has ended');
18 });
19
20 eos(writableStream, function(err) {
21         if (err) return console.log('stream had an error or closed early');
22         console.log('stream has finished');
23 });
24
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');
28 });
29
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');
33 });
34
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');
38 });
39
40 eos(readableStream, {error:false}, function(err) {
41         // do not treat emit('error', err) as a end-of-stream
42 });
43 ```
44
45 ## License
46
47 MIT