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
Usage
var channels =var stream =streamvar ch1 = streamvar ch2 = streamch1ch2ch1ch2stream
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