Sha256: 4e731d5bb1d9692a2511be7ffe5eb341c53388659a4a978830ce46360aa6bd3f

Contents?: true

Size: 1.63 KB

Versions: 196

Compression:

Stored size: 1.63 KB

Contents

#through

[![build status](https://secure.travis-ci.org/dominictarr/through.png)](http://travis-ci.org/dominictarr/through)
[![testling badge](https://ci.testling.com/dominictarr/through.png)](https://ci.testling.com/dominictarr/through)

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 if you use `this.queue(data)` instead of `this.emit('data', data)`.
* Use `this.pause()` and `this.resume()` to manage flow.
* Check `this.paused` to see current flow state. (`write` always returns `!this.paused`).

This function is the basis for most of the synchronous streams in 
[event-stream](http://github.com/dominictarr/event-stream).

``` js
var through = require('through')

through(function write(data) {
    this.queue(data) //data *must* not be null
  },
  function end () { //optional
    this.queue(null)
  })
```

Or, can also be used _without_ buffering on pause, use `this.emit('data', data)`,
and this.emit('end')

``` js
var through = require('through')

through(function write(data) {
    this.emit('data', data)
    //this.pause() 
  },
  function end () { //optional
    this.emit('end')
  })
```

## Extended Options

You will probably not need these 99% of the time.

### autoDestroy=false

By default, `through` emits close when the writable
and readable side of the stream has ended.
If that is not desired, set `autoDestroy=false`.

``` js
var through = require('through')

//like this
var ts = through(write, end, {autoDestroy: false})
//or like this
var ts = through(write, end)
ts.autoDestroy = false
```

## License

MIT / Apache2

Version data entries

196 entries across 172 versions & 19 rubygems

Version Path
pcp-server-ruby-sdk-0.0.6 node_modules/through/readme.markdown
pcp-server-ruby-sdk-0.1.0 node_modules/through/readme.markdown
reed_sdk-1.0.1 node_modules/through/readme.markdown
reed_sdk-1.0.0 node_modules/through/readme.markdown
sequenceserver-2.0.0 public/vendor/npm/through@2.3.8/readme.markdown
isomorfeus-puppetmaster-0.5.5 node_modules/through/readme.markdown
isomorfeus-puppetmaster-0.5.4 node_modules/through/readme.markdown
isomorfeus-puppetmaster-0.5.3 node_modules/through/readme.markdown
isomorfeus-puppetmaster-0.5.2 node_modules/through/readme.markdown
isomorfeus-puppetmaster-0.5.1 node_modules/through/readme.markdown
isomorfeus-puppetmaster-0.5.0 node_modules/through/readme.markdown
sequenceserver-2.0.0.rc8 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc7 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc6 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc5 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc4 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc3 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc2 public/vendor/npm/through@2.3.8/readme.markdown
sequenceserver-2.0.0.rc1 public/vendor/npm/through@2.3.8/readme.markdown
ilog-0.4.1 node_modules/through/readme.markdown