How to use the readable-stream.PassThrough function in readable-stream

To help you get started, we’ve selected a few readable-stream 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 nfroidure / gulp-ttf2eot / src / index.js View on Github external
if((!options.ignoreExt) && '.ttf' !== path.extname(file.path)) {
      stream.push(file); done();
      return;
    }

    // Fix for the vinyl clone method...
    // https://github.com/wearefractal/vinyl/pull/9
    if(options.clone) {
      if(file.isBuffer()) {
        stream.push(file.clone());
      } else {
        cntStream = file.contents;
        file.contents = null;
        newFile = file.clone();
        file.contents = cntStream.pipe(new Stream.PassThrough());
        newFile.contents = cntStream.pipe(new Stream.PassThrough());
        stream.push(newFile);
      }
    }

    file.path = replaceExtension(file.path, '.eot');

    // Buffers
    if(file.isBuffer()) {
      try {
        file.contents = new Buffer(ttf2eot(
          new Uint8Array(file.contents)
        ).buffer);
      } catch(err) {
        stream.emit('error', new PluginError(PLUGIN_NAME, err, {
          showStack: true,
        }));
github ipfs / js-ipfs-http-client / src / files-regular / get-readable-stream.js View on Github external
return (path, opts) => {
    opts = opts || {}

    const pt = new Stream.PassThrough({ objectMode: true })

    try {
      path = cleanCID(path)
    } catch (err) {
      if (!v.ipfsPath(path)) {
        return pt.destroy(err)
      }
    }

    const request = { path: 'get', args: path, qs: opts }

    // Convert the response stream to TarStream objects
    send.andTransform(request, TarStreamToObjects, (err, stream) => {
      if (err) { return pt.destroy(err) }

      pump(stream, pt)
github implydata / plywood / test / external / mySqlExternal.mocha.js View on Github external
}, () => {
      const stream = new PassThrough({ objectMode: true });
      setTimeout(() => { stream.end(); }, 1);
      return stream;
    });
github uber-node / ringpop-node / lib / request-proxy.js View on Github external
var checksum = head.ringpopChecksum;

    if (checksum !== ringpop.membership.checksum) {
        var err = InvalidCheckSumError({
            expected: ringpop.membership.checksum,
            actual: checksum
        });
        ringpop.logger.warn('handleRequest got invalid checksum', {
            err: err,
            url: url
        });
        ringpop.emit('requestProxy.checksumsDiffer');
        return cb(err);
    }

    var httpRequest = new PassThrough();
    httpRequest.url = url;
    httpRequest.headers = headers;
    httpRequest.method = method;
    httpRequest.httpVersion = httpVersion;

    httpRequest.end(body);

    var httpResponse = hammock.Response(onResponse);

    ringpop.logger.trace('handleRequest emitting request', {
        url: url
    });

    ringpop.emit('request', httpRequest, httpResponse, head);

    function onResponse(err, resp) {
github uber-node / tcurl / as-http.js View on Github external
TCurlAsHttp.prototype.send = function send() {
    var self = this;

    var hreq = PassThrough();
    hreq.end(self.body);
    hreq.url = self.endpoint;
    hreq.method = self.method;
    hreq.headers = self.headers;

    var hres = new HTTPResponse();
    self.asHttpClient.forwardToTChannel(self.subChannel, hreq, hres, {streamed: true}, onComplete);
    function onComplete(err) {
        if (err) {
            self.done();
            self.logger.error(err);
            return self.logger.exit();
        }
        self.done();
        self.logger.log(hres.statusCode);
        self.logger.log(hres.body);
github freeCodeCamp / camper-gitter-bot / wip / oauth / node_modules / express / node_modules / connect / node_modules / multiparty / index.js View on Github external
case '7bit':
    case '8bit':
    self.partTransferEncoding = 'binary';
    break;

    case 'base64': break;
    default:
    return new Error("unknown transfer-encoding: " + self.partTransferEncoding);
  }

  self.totalFieldCount += 1;
  if (self.totalFieldCount >= self.maxFields) {
    return new Error("maxFields " + self.maxFields + " exceeded.");
  }

  self.destStream = new stream.PassThrough();
  self.destStream.on('drain', function() {
    flushWriteCbs(self);
  });
  self.destStream.headers = self.partHeaders;
  self.destStream.name = self.partName;
  self.destStream.filename = self.partFilename;
  self.destStream.byteOffset = self.bytesReceived + offset;
  var partContentLength = self.destStream.headers['content-length'];
  self.destStream.byteCount = partContentLength ?
    parseInt(partContentLength, 10) :
    (self.bytesExpected - self.destStream.byteOffset -
     self.boundary.length - LAST_BOUNDARY_SUFFIX_LEN);

  self.emit('part', self.destStream);
  if (self.destStream.filename == null && self.autoFields) {
    handleField(self, self.destStream);
github webtorrent / create-torrent / index.js View on Github external
return () => {
    const s = new stream.PassThrough()
    s.end(buffer)
    return s
  }
}
github ipfs / js-ipfs-http-client / src / files-regular / ls-readable-stream.js View on Github external
return (args, opts, callback) => {
    if (typeof (opts) === 'function') {
      callback = opts
      opts = {}
    }

    try {
      args = cleanCID(args)
    } catch (err) {
      if (!IsIpfs.ipfsPath(args)) {
        return callback(err)
      }
    }

    const pt = new Stream.PassThrough({ objectMode: true })

    send({ path: 'ls', args: args, qs: opts }, (err, results) => {
      if (err) { return callback(err) }

      let result = results.Objects
      if (!result) {
        return callback(new Error('expected .Objects in results'))
      }

      result = result[0]
      if (!result) {
        return callback(new Error('expected one array in results.Objects'))
      }

      result = result.Links
      if (!Array.isArray(result)) {
github iarna / abraxas / task-client.js View on Github external
var ClientTask = module.exports = function ClientTask(callback,options) {
    if (!options) options = {};
    if (options.encoding == 'buffer') delete options.encoding;

    this.options = options;
    this.conn = null;
    this.completed = false;
    this.inprogress = 0;

    var accept = new stream.PassThrough(options.accept);
    var transmit = new stream.PassThrough(options.transmit);

    if (! options.encoding) options.encoding = this.options.defaultEncoding;
    if (options.encoding == 'buffer') delete options.encoding;
    if (options.encoding && (!options.accept || !options.accept.encoding)) {
        accept.setEncoding(options.encoding);
    }
    if (options.encoding && (!options.transmit || !options.transmit.encoding)) {
        transmit.setEncoding(options.encoding);
    }

    Task.call(this,accept,transmit,options);
    if (callback) {
        this.pipe(concat(function(data) { callback(null,(data instanceof Array && data.length == 1) ? data[0] : data) }));
        this.once('error', callback);
    }
github michaelnisi / pickup / example / spin.js View on Github external
function parse (p) {
  const reader = fs.createReadStream(p)
  const writer = new stream.PassThrough()
  reader.pipe(pickup()).pipe(writer)
}