How to use through3 - 10 common examples

To help you get started, we’ve selected a few through3 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 tmpfs / husk / lib / stream / parse / index.js View on Github external
// decorate chunk
      if(this.opts.field) {
        chunk[this.opts.field] = output;
      // mutate chunk
      }else{
        chunk = output;
      }
    }catch(e) {
      this.emit('error', e);
    }
  }
  this.push(chunk);
  cb();
}

module.exports = through.transform(transform, {ctor: Parse});
github tmpfs / husk / lib / stream / transform / index.js View on Github external
}

/**
 *  Transform function.
 */
function transform(chunk, encoding, cb) {
  if(typeof this.method === 'function') {
    // mutate chunk through all function calls
    // result of first call is passed to the next
    chunk = this.method.call(chunk, this);
  }
  this.push(chunk);
  cb();
}

module.exports = through.transform(transform, {ctor: Transform});
github tmpfs / husk / lib / stream / fs / index.js View on Github external
scope.push(chunk);
        cb();
      });
    // cannot handle content, expecting string, buffer or readable stream
    }else{
      this.push(chunk);
      cb();
    }
  // passthrough
  }else{
    this.push(chunk);
    cb();
  }
}

FileAsync.FileRead = through.transform(readTransform, {ctor: FileRead});
FileAsync.FileWrite = through.transform(writeTransform, {ctor: FileWrite});

module.exports = FileAsync;
github tmpfs / husk / lib / stream / process / index.js View on Github external
function transform(chunk, encoding, cb) {
  if(this.ps === undefined
    && this.info
    && this.info.previous
    && !(this.info.previous instanceof Process)) {
    this.start(chunk);
  }else{
    this.push(chunk);
    cb();
  }
}

/* for some magical reason flush must be declared */
function flush() {}

module.exports = through.transform(transform, flush, {ctor: Process});
github tmpfs / husk / lib / stream / prompt / index.js View on Github external
/**
 *  Transform function.
 */
function transform(chunk, encoding, cb) {
  // invoke the prompt method
  if(typeof this.method === 'function') {
    this.method.call(this, this.ps, chunk, encoding, cb);
  // pass through
  }else{
    this.push(chunk);
    cb();
  }
}

var Stream = through.transform(transform, {ctor: Prompt});


// static access to formatted prompt string data
Stream.getPrompt = function getPrompt(info, opts) {
  var ps = prompt(opts);
  return ps.format(info);
}

module.exports = Stream;
github tmpfs / husk / lib / stream / io / index.js View on Github external
function load(opts) {
  opts = opts || {};

  function transform(chunk, encoding, cb) {
    // TODO: handle URLs and protocols here
    if(chunk instanceof DuplexFile) {
      chunk.stream = fs.createReadStream(chunk.path);       
    }
    cb();
  }

  var Type = through.transform(transform);
  return new Type();
}
github tmpfs / husk / lib / stream / zlib / index.js View on Github external
if(source !== chunk) {
      // update contents reference for write() method
      chunk.contents = stream;
      this.push(chunk);
    }else{
      // push writable side of pipe if input chunk was readable stream
      this.push(stream);
    }
    cb();
  }else{
    this.push(chunk);
    cb();
  }
}

module.exports = through.transform(transform, {ctor: Zlib});
module.exports.types = types;
module.exports.methods = methods;
github tmpfs / husk / lib / stream / split / index.js View on Github external
/**
 *  Transform function.
 */
function transform(chunk, encoding, cb) {
  if(typeof chunk === 'string') {
    if(this.opts.trim) {
      chunk = chunk.trim();
    }
    chunk = chunk.split(this.opts.ptn);
  }
  this.push(chunk);
  cb();
}

module.exports = through.transform(transform, {ctor: Split});
github tmpfs / husk / lib / stream / each / index.js View on Github external
function transform(chunk, encoding, cb) {
  if(chunk) {
    var k, v;
    for(k in chunk) {
      v = this.method.call(chunk[k], chunk, this);
      if(v !== undefined) {
        this.push(v);
      }else{
        this.push(chunk[k]);
      }
    }
  }
  cb();
}

module.exports = through.transform(transform, {ctor: Each});
github tmpfs / husk / lib / stream / url / index.js View on Github external
&& !Array.isArray(chunk) && !Buffer.isBuffer(chunk)) {
    res = uri.format(chunk);
  }
  if(res && opts.field && chunk) {
    chunk[opts.field] = res;
  }
  if(res === undefined || opts.passthrough || opts.field) {
    this.push(chunk);
  }
  if(res && !opts.field) {
    this.push(res);
  }
  cb();
}

module.exports = through.transform(transform, {ctor: URL});

through3

Extend stream classes.

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Popular through3 functions