Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
through | 2.3.8 | 4.36 kB | MIT | prod |
Through is an easy-to-use JavaScript module that lets developers create a stream that is both readable and writable. It's a core building block for most of the synchronous streams in event-stream. Optionally, through can be used with write and end methods to manage stream data. It also handles pause/resume logic automatically when you use this.queue(data)
as opposed to this.emit('data', data)
. You can check this.paused
to observe the current flow state. Through is particularly helpful for those looking to simplify their stream construction in Node.js.
Through can be used in a few ways in JavaScript code. To use through
, you first need to require it using the require
function. Here is an example of using through with the write
and optional end
methods:
var through = require('through')
through(function write(data) {
this.queue(data)
},
function end () {
this.queue(null)
})
You could also use it without buffering on pause. Here's a code snippet for this:
var through = require('through')
through(function write(data) {
this.emit('data', data)
},
function end () {
this.emit('end')
})
The autoDestroy
property can be set to false
if you don't want through
to automatically emit close when the readable and writable aspects of the stream have ended.
var through = require('through')
var ts = through(write, end, {autoDestroy: false})
//or
var ts = through(write, end)
ts.autoDestroy = false
The documentation for through
can be found directly in the source code and the readme file of the npm package on GitHub. This contains all the basic information needed to comprehend and utilize the library. If you're looking to understand through
in-depth, though, the codebase itself is relatively simple and well-suited to a detailed read-through for seasoned JavaScript developers.