Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
multiplex-demultiplex object streams across any text stream.
var MuxDemux = require('..')
var net = require('net')
var mdm1 = MuxDemux()
var mdm2 =
MuxDemux(function (stream) {
stream.on('data', console.log.bind(console))
})
net.createServer(function (con) {
con.pipe(mdm2).pipe(con)
}).listen(8642, function () {
var con = net.connect(8642)
con.pipe(mdm1).pipe(con)
var ds = mdm1.createWriteStream('times')
setInterval(function () {
ds.write(new Date().toString())
}, 1e3)
})
#API
the API browser-stream
var MuxDemux = require('mux-demux')
var client = MuxDemux()
var server = MuxDemux()
client.pipe(server).pipe(client)
server.on('connection', function (stream) {
// inspect stream.meta to decide what this stream is.
})
client.createWriteStream(meta)
client.createReadStream(meta)
client.createStream(meta)
there is actually no distinction between clients and servers.
if both sides are listening on('connection',...)
then both sides may call create{Write,Read,}Stream(meta)
and initiate new streams.
Creates a MuxDemux stream. Optionally pass in an options hash
{
error: Boolean,
wrapper: function (stream) {...}
}
If the error option is set to true then MuxDemux will emit errors on the streams on unexpected disconnects. othewise, it will just emit 'end' on those streams.
wrapper
be used to change the serialization format used by mux-demux
,
by default, line seperated json is used. see examples below
both mux-demux end points must use the same wrapper.
options
is optional. MuxDemux(onConnection)
is a shortcut
for MuxDemux().on('connection', onConnection)
open a ReadableStream
from the other side.
returns a ReadableStream
.
the other side of connection will emit a writable stream that is connected to this stream.
open a WritableStream
to the other side.
returns a WritableStream
, the other side will emit a ReadableStream
connected to this stream.
open a Stream
to the other side which is both readable and writable.
returns a Stream
, the other side will emit a Stream
connected to this stream.
note to self, references to a class (
Stream
) should be capitalized, and in backticks. references to an instance should be lowercase, and not in backticks unless refuring to a specific variable in a code example.
A stream of plain old js objects.
new MuxDemux({wrapper: function (stream) { return stream } })
A stream of msgpack.
var es = require('event-stream')
var ms = require('msgpack-stream')
new MuxDemux({wrapper: function (stream) {
return es.pipeline(ms.createDecodeStream(), stream, ms.createEncodeStream())
}})
there is one addition to the stream interface. call stream.error(err)
will send an error that will be emitted at the other side of the stream.
this is useful for sending 404 like messages to clients, etc.
FAQs
multiplex streams
The npm package mux-demux receives a total of 3,535 weekly downloads. As such, mux-demux popularity was classified as popular.
We found that mux-demux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.