Exemple #1
0
Multiplex.prototype._push = function (data) {
  if (!this._missing) {
    this._ptr = 0
    this._state = 0
    this._message = null
  }

  if (this._type === 0) { // open
    if (this.destroyed || this._finished) return

    var name = this._binaryName
      ? data
      : (data.toString() || this._channel.toString())

    var channel

    if (this._receiving && this._receiving[name]) {
      channel = this._receiving[name]
      delete this._receiving[name]
      this._addChannel(channel, this._channel, this._list)
    } else {
      channel = new Channel(name, this, this._options)
      this.emit('stream', this._addChannel(
        channel,
        this._channel,
        this._list), channel.name)
    }
    return
  }

  var stream = this._list[this._channel] ||
    this._remote[this._channel] ||
    this._local[this._channel]

  if (!stream) { return }

  switch (this._type) {
    case 5: // local error
    case 6: // remote error
      var error = new Error(data.toString() || 'Channel destroyed')
      stream._destroy(error, false)
      return

    case 3: // local end
    case 4: // remote end
      stream.push(null)
      return

    case 1: // local packet
    case 2: // remote packet
      if (!stream.push(data)) {
        this._awaitChannelDrains++
        stream._awaitDrain++
      }
      return
  }
}
Exemple #2
0
      fs.readFile(adapter.datadir + key, function (err, contents) {
        if (err) {
          return stream.emit('error', err)
        }

        current++
        stream.push({ key: key, value: contents.toString() })
      })
 return new Promise((resolve, reject) => {
   try {
     const stream = new Stream()
     let processedState = ''
     stream
       .on('data', data => {
         processedState += cryptor.process(data.toString())
       })
       .on('end', () => {
         processedState += cryptor.finalize()
         resolve(processedState)
       })
     stream.push(state)
     stream.push(null)
   } catch (err) {
     reject(err)
   }
 })
 txs.forEach(function (txInfo) {
   stream.push({
     height: txInfo.blockHeight,
     blockId: txInfo.blockId,
     confirmations: txInfo.__confirmations,
     blockTimestamp: txInfo.__blockTimestamp,
     tx: bitcoin.Transaction.fromHex(txInfo.txHex)
   })
 })
Exemple #5
0
function gulpPluginCb(file, pluginStream, cb) {
  var fileStream = new Readable({objectMode: true});
  var concatStream = concat(callBack);

  fileStream.on('error', handleError);
  pluginStream.on('error', handleError);

  fileStream.push(file);
  fileStream.push(null);
  fileStream.pipe(pluginStream).pipe(concatStream);

  function handleError(err) {
    cb(err);
  }

  function callBack(objs) {
    cb(null, objs[0]);
  }
}
Exemple #6
0
    runRequestFunc(self.buildRequest(), function (err, resp) {
      if(err && err.retryable) {
        return setTimeout(startRead, 1000);
      } else if(err) {
        return stream.emit('error', err);
      } else {
        lastEvaluatedKey = resp.LastEvaluatedKey;

        if(!self.options.loadAll || !lastEvaluatedKey) {
          performRequest = false;
        }

        stream.push(resp);

        if(!self.options.loadAll || !lastEvaluatedKey) {
          stream.push(null);
        }
      }

    });
Exemple #7
0
    read: function () {
      var stream = this
      var key = items[current]

      if (!key) {
        return stream.push(null)
      }
      key = new Buffer(key, 'utf8').toString('base64')

      fs.readFile(adapter.datadir + key, function (err, contents) {
        if (err) {
          return stream.emit('error', err)
        }

        current++
        stream.push({ key: key, value: contents.toString() })
      })
    }
Exemple #8
0
 this.on('end', function() {
   stream.emit('close'); // notify readers that query has completed
   stream.push(null); // pushing null, indicating EOF
 });
Exemple #9
0
 this.on('result', function(row) {
   if (!stream.push(row)) {
     self._connection.pause();
   }
   stream.emit('result', row); // replicate old emitter
 });
Exemple #10
0
 this.on('end', function() {
   stream.push(null);  // pushing null, indicating EOF
 });
function arrStream(l) {
    var rs = new Readable({ objectMode: true });
    l.forEach(function(_) { rs.push(_); });
    rs.push(null);
    return rs;
}
function rangeStream(a, b) {
    var rs = new Readable({ objectMode: true });
    for (var i = a; i < b; i++) { rs.push(i); }
    rs.push(null);
    return rs;
}
Exemple #13
0
  _push (data/* : Buffer */) {
    this.log('_push', data.length)
    if (!this._missing) {
      this._ptr = 0
      this._state = 0
      this._message = null
    }

    if (this._type === 0) { // open
      this.log('open', this._channel)
      if (this.destroyed || this._finished) {
        return
      }

      let name
      if (this._binaryName) {
        name = data
      } else {
        name = data.toString() || this._channel.toString()
      }
      this.log('open name', name)
      let channel
      if (this._receiving && this._receiving[name]) {
        channel = this._receiving[name]
        delete this._receiving[name]
        this._addChannel(channel, this._channel, this._list)
      } else {
        channel = new Channel(name, this, this._options)
        this.emit('stream', this._addChannel(
          channel,
          this._channel,
          this._list), channel.name)
      }
      return
    }

    const stream = this._list[this._channel]
    if (!stream) {
      return
    }

    switch (this._type) {
      case 5: // local error
      case 6: { // remote error
        const error = new Error(data.toString() || 'Channel destroyed')
        stream.local = false
        stream.destroy(error)
        return
      }

      case 3: // local end
      case 4: { // remote end
        stream.push(null)
        return
      }

      case 1: // local packet
      case 2: // remote packet
        if (!stream.push(data)) {
          this._awaitChannelDrains++
          stream._awaitDrain++
        }
        break
      default: // no action
    }
  }
Exemple #14
0
 filter.onEnd  = ()   => { stream.push(null); };
Exemple #15
0
 filter.onData = data => { stream.push(data); };