Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mux-demux

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mux-demux

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.6K
decreased by-60.65%
Maintainers
1
Weekly downloads
 
Created
Source

MuxDemux

multiplex-demultiplex object streams across any text stream.

var MuxDemux = require('..')
var net = require('net')

var mdm1 = MuxDemux()
var mdm2 = MuxDemux()

mdm2.on('connection', function (stream) {
  stream.on('data', function (date) {
    console.log(date)
  })
})

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.

createReadStream (meta)

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.

createWriteStream (meta)

open a WritableStream to the other side. returns a WritableStream, the other side will emit a ReadableStream connected to this stream.

createStream (meta)

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.

FAQs

Package last updated on 31 Jul 2012

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc