How to use the duplexify.obj 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 tjmehta / primus-graphql / test / data-handler.unit.js View on Github external
onCompleted: sinon.stub()
      }
    }
    this.mocks.QueryExecutor = sinon.stub().returns(this.mocks.queryExecutor)
    this.mocks.Responder = sinon.stub().returns(this.mocks.responder)
    this.mocks.SubscribeCallbacks = sinon.stub().returns(this.mocks.subscribeCallbacks)
    // proxyquire
    this.DataHandler = proxyquire('../src/server/data-handler.js', {
      './active-subscriptions.js': this.mocks.activeSubscriptions,
      './query-executor.js': this.mocks.QueryExecutor,
      './responder.js': this.mocks.Responder,
      './subscribe-callbacks.js': this.mocks.SubscribeCallbacks
    })
    var toServer = through2.obj()
    var toClient = through2.obj()
    this.primusClient = duplexify.obj(toServer, toClient)
    this.spark = duplexify.obj(toClient, toServer)
    this.spark.id = 'sparkId'
  })
github urbanjs / urbanjs-tools / src / utils / helper-stream.js View on Github external
emitError: true
    }, options);

    const forkStream = new ForkStream({
      classifier: (file, cb) => cb(null, !!condition(file))
    });

    forkStream.a.pipe(conditionStream);

    // merge-stream package cannot be updated because it emits the error
    // from conditionStream to mergedStream
    const mergedStream = mergeStream(forkStream.b, conditionStream);
    const outStream = through2.obj();
    mergedStream.pipe(outStream);

    const duplexStream = duplexify.obj(forkStream, outStream);

    if (options.emitError) {
      conditionStream.on('error', err => duplexStream.emit('error', err));
    }

    return duplexStream;
  }
};
github googleapis / google-cloud-node / packages / common-grpc / src / service.js View on Github external
GrpcService.prototype.requestWritableStream = function(protoOpts, reqOpts) {
  var stream = protoOpts.stream = protoOpts.stream || duplexify.obj();

  if (global.GCLOUD_SANDBOX_ENV) {
    return stream;
  }

  var self = this;

  if (!this.grpcCredentials) {
    // We must establish an authClient to give to grpc.
    this.getGrpcCredentials_(function(err, credentials) {
      if (err) {
        stream.destroy(err);
        return;
      }

      self.grpcCredentials = credentials;
github vweevers / win-detect-browsers / lib / cscript-stream.js View on Github external
function createStream (script, opts_) {
  var opts = opts_ || {}
  var duplex = duplexify.obj(null, null)

  function errback(err) {
    if (err) duplex.destroy(err)
  }

  // Find the cscript binary. If we're on 64-bit Windows and 32-bit
  // Node.js then prefer the native "Sysnative\cscript.exe", because
  // otherwise we would be redirected to "SysWow64\cscript.exe" and
  // then be unable to access the native registry (without resorting
  // to the slower ExecMethod). See also win-detect-browsers#18.
  wbin('cscript', { native: opts.native }, function(err, bin) {
    if (err) return duplex.destroy(err)

    var args = ['//Nologo', '//B', resolve(script)].concat(opts.args || [])
    var child = execFile(bin, args, errback)
github maxogden / websocket-stream / stream.js View on Github external
// special constructor treatment for native websockets in browsers, see
    // https://github.com/maxogden/websocket-stream/issues/82
    if (isNative && isBrowser) {
      socket = new WS(target, protocols)
    } else {
      socket = new WS(target, protocols, options)
    }

    socket.binaryType = 'arraybuffer'
  }

  // was already open when passed in
  if (socket.readyState === socket.OPEN) {
    stream = proxy
  } else {
    stream = duplexify.obj()
    socket.onopen = onopen
  }

  stream.socket = socket

  socket.onclose = onclose
  socket.onerror = onerror
  socket.onmessage = onmessage

  proxy.on('close', destroy)

  var coerceToBuffer = !options.objectMode

  function socketWriteNode(chunk, enc, next) {
    // avoid errors, this never happens unless
    // destroy() is called
github maxogden / dat-core / index.js View on Github external
Dat.prototype.createMergeStream = function (headA, headB, opts) {
  if (!this.opened) return this._createProxyStream(this.createMergeStream, [headA, headB, opts])
  if (!opts) opts = {}
  if (!headA || !headB) throw new Error('You need to provide two nodes')

  debug('createMergeStream', headA, headB, opts)

  var valueEncoding = this._getValueEncoding(opts.valueEncoding)

  var self = this
  var operations = []
  var stream = duplexify.obj()

  var write = function (data, enc, cb) {
    operations.push({
      type: data.type === 'del' ? DELETE : PUT,
      dataset: data.dataset,
      key: data.key,
      value: valueEncoding.encode(data.value)
    })

    cb()
  }

  stream.on('prefinish', function () {
    stream.cork()
    self._commit([headA, headB], messages.COMMIT_TYPE.DATA, operations, opts.message, function (err, head) {
      if (err) return stream.destroy(err)
github mikejoyceio / map / node_modules / gulp-imagemin / node_modules / imagemin / node_modules / vinyl-fs / lib / src / index.js View on Github external
.pipe(resolveSymlinks(options))
    .pipe(through.obj(createFile));

  if (options.since != null) {
    outputStream = outputStream
      .pipe(filterSince(options.since));
  }

  if (options.read !== false) {
    outputStream = outputStream
      .pipe(getContents(options));
  }

  if (options.passthrough === true) {
    inputPass = through.obj();
    outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
  }
  if (options.sourcemaps === true) {
    outputStream = outputStream
      .pipe(sourcemaps.init({loadMaps: true}));
  }
  globStream.on('error', outputStream.emit.bind(outputStream, 'error'));
  return outputStream;
}
github stevelacy / exceljs-transform-stream / index.js View on Github external
if (!opts.objectMode) {
          second.push(JSON.stringify(item))
          return
        }
        second.push(item)
      })
    })
    second.end()
  })
    .catch((err) => {
      if (err.message && err.message.indexOf('is this a zip') !== -1) {
        err = new Error('Legacy XLS files are not supported, use an XLSX file instead!')
      }
      second.emit('error', err)
    })
  return duplex.obj(input, second)
}
github mqttjs / MQTT.js / lib / connect / wx.js View on Github external
var websocketSubProtocol =
    (opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
      ? 'mqttv3.1'
      : 'mqtt'

  setDefaultOpts(opts)

  var url = buildUrl(opts, client)
  socketTask = wx.connectSocket({
    url: url,
    protocols: websocketSubProtocol
  })

  proxy = buildProxy()
  stream = duplexify.obj()
  stream._destroy = function (err, cb) {
    socketTask.close({
      success: function () {
        cb && cb(err)
      }
    })
  }

  var destroyRef = stream.destroy
  stream.destroy = function () {
    stream.destroy = destroyRef

    var self = this
    process.nextTick(function () {
      socketTask.close({
        fail: function () {
github arso-project / archipel / packages / common / rpc / streambus.js View on Github external
resolveStream (arg, id) {
    var { streamType, objectMode } = arg
    var ds = objectMode ? duplexify.obj() : duplexify()

    if (streamType & READABLE) {
      var rs = through({ objectMode })
      var rsT = this.getTransportStream(id, READABLE, rs)
      pump(rsT, maybeConvert(false, objectMode), rs)
      ds.setReadable(rs)
    }
    if (streamType & WRITABLE) {
      var ws = through({ objectMode })
      var wsT = this.getTransportStream(id, WRITABLE, ws)
      pump(ws, maybeConvert(objectMode, false), wsT)
      ds.setWritable(ws)
    }

    return ds
  }

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 5 months ago

Package Health Score

77 / 100
Full package analysis

Popular duplexify functions