🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

stream-channels

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-channels

Simple one-way stream multiplexer with very few features

latest
Source
npmnpm
Version
1.4.1
Version published
Maintainers
1
Created
Source

stream-channels

Simple one-way stream multiplexer with very few features. For two-way (full duplex) multiplexing see the multiplex module.

npm install stream-channels

build status

Usage

var channels = require('stream-channels')
var stream = channels()

stream.on('channel', function (channel) {
  console.log('new channel')
  channel.on('data', console.log)
  channel.on('end', function () {
    console.log('(no more data)')
  })
})

var ch1 = stream.createChannel()
var ch2 = stream.createChannel()

ch1.write('hello')
ch2.write('world')

ch1.end()
ch2.end()

stream.pipe(stream)

API

var stream = channels([options], [onchannel])

Create a new instance. Options include:

{
  limit: maxChannelsAllowedOpen // defaults to 1024
}

var writeableStream = stream.createChannel()

Create a new channel.

stream.on('channel', readableStream)

Emitted when a remote creates a new channel. Will emit the data the remote writes to it.

stream.setTimeout(ms, [ontimeout])

Emit a timeout when if the stream is inactive for ~ms milliseconds. Will start a heartbeat as well.

Wire Protocol

The wire protocol is as follows.

------------------------------
| length | channel-id | data |
------------------------------
  • Length is a varint containing the binary length of channel-id and data.
  • Channel id is a varint representing the current channel.
  • Data is the buffer you wrote to a channel

Channels are lazily opened., The first time you receive data on a channel id, that channel is opened. Receiving an empty data buffer indicates that the channel is closed.

Messages received with length 0 should be ignored and can be used as a keep alive signal.

Back pressure

Back pressure will trigger on all channels when the slowest channel starts to back pressure.

License

MIT

FAQs

Package last updated on 02 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts