How to use the duplexify.call function in duplexify

To help you get started, we’ve selected a few duplexify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mqttjs / mqtt-connection / connection.js View on Github external
// defer piping, so consumer can attach event listeners
  // otherwise we might lose events
  process.nextTick(() => {
    duplex.pipe(this._parser)
  })

  this._generator.on('error', this.emit.bind(this, 'error'))
  this._parser.on('error', this.emit.bind(this, 'error'))

  this.stream = duplex

  duplex.on('error', this.emit.bind(this, 'error'))
  duplex.on('close', this.emit.bind(this, 'close'))

  Duplexify.call(this, this._generator, this._parser, { objectMode: true })

  // MQTT.js basic default
  if (opts.notData !== true) {
    var that = this
    this.once('data', function (connectPacket) {
      that.setOptions(connectPacket)
      that.on('data', emitPacket)
      if (cb) {
        cb()
      }
      that.emit('data', connectPacket)
    })
  }
}
github mafintosh / stream-channels / index.js View on Github external
function StreamChannels (opts, onchannel) {
  if (!(this instanceof StreamChannels)) return new StreamChannels(opts, onchannel)
  if (typeof opts === 'function') {
    onchannel = opts
    opts = null
  }
  if (!opts) opts = {}

  duplexify.call(this)

  var self = this

  this.destroyed = false
  this.limit = opts.limit || 1024
  this.state = null // set by someone else. here for perf

  this._outgoing = []
  this._incoming = []
  this._waiting = 0
  this._encode = new Sink()
  this._decode = lpstream.decode({allowEmpty: true, limit: opts.messageLimit || 5 * 1024 * 1024})
  this._decode.on('data', parse)

  this._keepAlive = 0
  this._remoteKeepAlive = 0
github mafintosh / hyperlog / lib / protocol.js View on Github external
this.on('finish', function () {
    debug('finished')
    self.finalize()
  })

  this._decoder.pipe(parse)

  if (this._process) {
    this._process.pipe(through.obj(function (node, enc, cb) {
      self.emit('node', node, cb) || cb()
    }))
  }

  var hwm = opts.highWaterMark || 16
  Duplexify.call(this, this._decoder, this._encoder, frame ? {} : {objectMode: true, highWaterMark: hwm})
}
github sx1989827 / DOClever / node_modules / pumpify / index.js View on Github external
var Pumpify = function() {
    var streams = toArray(arguments)
    if (!(this instanceof Pumpify)) return new Pumpify(streams)
    Duplexify.call(this, null, null, opts)
    if (streams.length) this.setPipeline(streams)
  }
github sx1989827 / DOClever / Desktop / node_modules / pumpify / index.js View on Github external
var Pumpify = function() {
    var streams = toArray(arguments)
    if (!(this instanceof Pumpify)) return new Pumpify(streams)
    Duplexify.call(this, null, null, opts)
    if (streams.length) this.setPipeline(streams)
  }
github mafintosh / hyperdrive / lib / protocol.js View on Github external
function Protocol (opts) {
  if (!(this instanceof Protocol)) return new Protocol(opts)
  if (!opts) opts = {}

  duplexify.call(this)

  var self = this

  this.inflight = 0
  this.id = opts.id || crypto.randomBytes(32)
  this.remoteId = null

  this._parser = lpstream.decode({limit: MAX_MESSAGE})
  this._generator = lpstream.encode()
  this._parser.on('data', parse)
  this._handshook = false

  this._channels = {}
  this._remote = []
  this._local = ids()
github mafintosh / pumpify / index.js View on Github external
var Pumpify = function() {
    var streams = toArray(arguments)
    if (!(this instanceof Pumpify)) return new Pumpify(streams)
    Duplexify.call(this, null, null, opts)
    if (streams.length) this.setPipeline(streams)
  }
github mafintosh / peervision / protocol.js View on Github external
function Protocol () {
  if (!(this instanceof Protocol)) return new Protocol()

  var self = this
  var encode = lpstream.encode()
  var decode = lpstream.decode()

  this._encoder = encode
  this._requests = []

  decode.on('data', function (data) {
    self._decode(data)
  })

  duplexify.call(this, decode, encode)
}
github weixin / Miaow / node_modules / pumpify / index.js View on Github external
var Pumpify = function() {
    var streams = toArray(arguments)
    if (!(this instanceof Pumpify)) return new Pumpify(streams)
    Duplexify.call(this, null, null, opts)
    if (streams.length) this.setPipeline(streams)
  }
github mafintosh / peervision / lib / protocol.js View on Github external
function ProtocolStream (opts) {
  if (!(this instanceof ProtocolStream)) return new ProtocolStream(opts)
  if (!opts) opts = {}

  this._encode = lpstream.encode()
  this._decode = lpstream.decode({limit: 5 * 1024 * 1024})
  this._requests = []
  this._handshook = false
  this.destroyed = false

  duplexify.call(this, this._decode, this._encode)
  var self = this

  this._decode.on('data', function (data) {
    self._parse(data)
  })

  this._send(0, opts)
}

duplexify

Turn a writable and readable stream into a streams2 duplex stream with support for async initialization and streams1/streams2 input

MIT
Latest version published 8 months ago

Package Health Score

74 / 100
Full package analysis

Popular duplexify functions