readme.markdown
1#through
2
3[![build status](https://secure.travis-ci.org/dominictarr/through.png)](http://travis-ci.org/dominictarr/through)
4[![testling badge](https://ci.testling.com/dominictarr/through.png)](https://ci.testling.com/dominictarr/through)
5
6Easy way to create a `Stream` that is both `readable` and `writable`.
7
8* Pass in optional `write` and `end` methods.
9* `through` takes care of pause/resume logic if you use `this.queue(data)` instead of `this.emit('data', data)`.
10* Use `this.pause()` and `this.resume()` to manage flow.
11* Check `this.paused` to see current flow state. (`write` always returns `!this.paused`).
12
13This function is the basis for most of the synchronous streams in
14[event-stream](http://github.com/dominictarr/event-stream).
15
16``` js
17var through = require('through')
18
19through(function write(data) {
20 this.queue(data) //data *must* not be null
21 },
22 function end () { //optional
23 this.queue(null)
24 })
25```
26
27Or, can also be used _without_ buffering on pause, use `this.emit('data', data)`,
28and this.emit('end')
29
30``` js
31var through = require('through')
32
33through(function write(data) {
34 this.emit('data', data)
35 //this.pause()
36 },
37 function end () { //optional
38 this.emit('end')
39 })
40```
41
42## Extended Options
43
44You will probably not need these 99% of the time.
45
46### autoDestroy=false
47
48By default, `through` emits close when the writable
49and readable side of the stream has ended.
50If that is not desired, set `autoDestroy=false`.
51
52``` js
53var through = require('through')
54
55//like this
56var ts = through(write, end, {autoDestroy: false})
57//or like this
58var ts = through(write, end)
59ts.autoDestroy = false
60```
61
62## License
63
64MIT / Apache2
65