A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/lib/obj-multiplex.js

41 lines
905 B

const through = require('through2')
module.exports = ObjectMultiplex
9 years ago
function ObjectMultiplex (opts) {
opts = opts || {}
// create multiplexer
9 years ago
var mx = through.obj(function (chunk, enc, cb) {
var name = chunk.name
var data = chunk.data
var substream = mx.streams[name]
if (!substream) {
console.warn('orphaned data for stream ' + name)
} else {
substream.push(data)
}
return cb()
})
mx.streams = {}
// create substreams
9 years ago
mx.createStream = function (name) {
var substream = mx.streams[name] = through.obj(function (chunk, enc, cb) {
mx.push({
name: name,
data: chunk,
})
return cb()
})
9 years ago
mx.on('end', function () {
return substream.emit('end')
})
if (opts.error) {
9 years ago
mx.on('error', function () {
return substream.emit('error')
})
}
return substream
}
return mx
}