through
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

through

simplified stream construction

2.3.8  •  Published 4 years ago  •  by Dominic Tarr  •  MIT License

#through

build status testling badge

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.

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’)

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.

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

Popularity

Weekly Downloads
8.4M
Stars
666

Maintenance

Development

Last ver 4 years ago
Created 7 years ago
Last commit 4 years ago
12 days between commits

Technology

Node version: 2.3.1
0 unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

12 contributors
Dominic Tarr
Maintainer, 83 commits, 11 merges
Works at Protozoa
Roman Shtylman
2 commits, 1 PRs
Lars-Magnus Skog
2 commits
Isaac Z. Schlueter
1 commits, 1 PRs
Works at npm, Inc.
Raynos
1 commits, 2 PRs
Works at Uber
Jeff Barczewski
1 commits, 1 PRs
Works at CodeWinds / Inspired Horizons

Tags

stream
streams
user-streams
pipe
Ready for the next level?
Join Devstore's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
© 2019 Devstore, Inc.
Devstore helps developers find and use open-source packages, so they can focus on building amazing things