1 | #through
|
2 |
|
3 | [![build status](https://secure.travis-ci.org/dominictarr/through.png)](http://travis-ci.org/dominictarr/through)
|
4 |
|
5 | Easy way to create a `Stream` that is both `readable` and `writable`. Pass in optional `write` and `end` methods. `through` takes care of pause/resume logic.
|
6 | Use `this.pause()` and `this.resume()` to manage flow.
|
7 | Check `this.paused` to see current flow state. (write always returns `!this.paused`)
|
8 |
|
9 | this function is the basis for most of the syncronous streams in [event-stream](http://github.com/dominictarr/event-stream).
|
10 |
|
11 | ``` js
|
12 | var through = require('through')
|
13 |
|
14 | through(function write(data) {
|
15 | this.emit('data', data)
|
16 | //this.pause()
|
17 | },
|
18 | function end () { //optional
|
19 | this.emit('end')
|
20 | })
|
21 |
|
22 | ```
|