How to use the readable-stream.Transform.prototype 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 zemirco / json2csv-stream / benchmark / run.js View on Github external
//    });
//  }, function(err) {
//    console.log('done');
//    console.log(durations);
//  }
//);

function SimpleProtocol(options) {
  if (!(this instanceof SimpleProtocol))
    return new SimpleProtocol(options);

  Transform.call(this, options);
}

SimpleProtocol.prototype = Object.create(
  Transform.prototype, { constructor: { value: SimpleProtocol }});

SimpleProtocol.prototype._transform = function(chunk, encoding, done) {
  chunk = chunk.toString().toUpperCase();
  this.push(chunk);
};

var count = 0;
var durations = [];

//var reader = fs.createReadStream('in.json');
//var parser = new SimpleProtocol();
//var writer = fs.createWriteStream('out.csv');
//var start = Date.now();
//reader.pipe(parser).pipe(writer);
//reader.on('end', function() {
//  var duration = Date.now() - start;
github mixu / gluejs / lib / commonjs / wrap-cjs.js View on Github external
// package wrapper
var Transform = require('readable-stream').Transform,
    umd = require('umd');

function WrapCJS(options) {
  Transform.call(this, options);
  this.opts = options || {};
  this.first = true;
}

WrapCJS.prototype = Object.create(Transform.prototype, { constructor: { value: WrapCJS }});

WrapCJS.prototype.writePrelude = function() {
  if (!this.first) {
    return;
  }
  if (this.opts.standalone) {
    return this.push(umd.prelude(this.opts.standalone).trim() + 'return ');
  }
  if (false) {
    return this.push((this.opts.externalRequireName || 'require') + '=');
  }
};

WrapCJS.prototype._transform = function(chunk, encoding, done) {
  if (this.first) {
    this.writePrelude();
github bauerca / dynapack / index.js View on Github external
deps.write = function(dep, encoding, callback) {
    var path = dep.path;
    //console.log('dep', dep);

    if (path in pack._loading) {
      pack._loading[path]++;
    }
    else {
      pack._loading[path] = 1;
    }

    Transform.prototype.write.call(this, dep, encoding, callback);
  };
github mixu / gluejs / lib / file-tasks / stream-size.js View on Github external
var Transform = require('readable-stream').Transform;

function WrapCJS(options) {
  Transform.call(this, options);
  this.opts = options || {};
  this.length = 0;
}

WrapCJS.prototype = Object.create(Transform.prototype, { constructor: { value: WrapCJS }});

WrapCJS.prototype._transform = function(chunk, encoding, done) {
  this.length += chunk.length;
  done(null, chunk);
};

WrapCJS.prototype._flush = function(done) {
  if (this.opts.onDone) {
    this.opts.onDone(this.length);
  }
  done();
};

module.exports = function(options) {
  var instance = new WrapCJS(options);
  return {
github archiverjs / node-compress-commons / lib / archivers / archive-output-stream.js View on Github external
ArchiveOutputStream.prototype.write = function(chunk, cb) {
  if (chunk) {
    this.offset += chunk.length;
  }

  return Transform.prototype.write.call(this, chunk, cb);
};
github mixu / gluejs / lib / file-tasks / wrap-commonjs-web.js View on Github external
var Transform = require('readable-stream').Transform;

function WrapCJS(options) {
  Transform.call(this, options);
  this.opts = options || {};
  this.first = true;
}

WrapCJS.prototype = Object.create(Transform.prototype, { constructor: { value: WrapCJS }});

WrapCJS.prototype.writeFirst = function() {
  this.push('function(module, exports, require){\n');
  if(this.opts['source-url']) {
    this.push('eval(');
  }
  this.first = false;
};

WrapCJS.prototype._transform = function(chunk, encoding, done) {
  if(this.first) {
    this.writeFirst();
  }
  if(this.opts['source-url']) {
    this.push(JSON.stringify(chunk.toString())+'+');
  } else {
github levelgraph / levelgraph / lib / solutionsfilterstream.js View on Github external
return;
    }

    if (context) {
      that.push(context);
    }

    if (that._lastDone) {
      that._lastDone();
      that._lastDone = null;
    }
  };
}

SolutionsFilterStream.prototype = Object.create(
  Transform.prototype,
  { constructor: { value: SolutionsFilterStream } }
);

SolutionsFilterStream.prototype._transform = function solutionsTransform(context, encoding, done) {
  this._lastDone = done;
  this._filter(context, this._doPush);
};

module.exports = SolutionsFilterStream;
github mixu / gluejs / lib / file-tasks / wrap-json-web.js View on Github external
var Transform = require('readable-stream').Transform;

function WrapCJS(options) {
  Transform.call(this, options);
  this.opts = options || {};
  this.first = true;
  this.buffer = '';
}

WrapCJS.prototype = Object.create(Transform.prototype, { constructor: { value: WrapCJS }});

WrapCJS.prototype.writeFirst = function() {
  this.push('function(module, exports, require){\n');
  this.push('module.exports = ');
  this.first = false;
};

WrapCJS.prototype._transform = function(chunk, encoding, done) {
  if(this.first) {
    this.writeFirst();
  }
  this.buffer += chunk;
  done();
};

WrapCJS.prototype._flush = function(done) {
github levelgraph / levelgraph / lib / navigator.js View on Github external
, wrapCallback = require('./utilities').wrapCallback;

function NavigatorStream(options) {
  if (!(this instanceof NavigatorStream)) {
    return new NavigatorStream(options);
  }

  options.objectMode = true;

  Transform.call(this, options);

  this._lastElement = options._lastElement;
}

NavigatorStream.prototype = Object.create(
  Transform.prototype,
  { constructor: { value: NavigatorStream } }
);

NavigatorStream.prototype._transform = function(data, encoding, done) {
  var value = data[this._lastElement.name] || this._lastElement;
  this.push(value);
  done();
};

function Navigator(options) {
  if (!(this instanceof Navigator)) {
    return new Navigator(options);
  }

  this.db = options.db;
  this._conditions = [];
github michaelnisi / pickup / index.js View on Github external
Pickup.prototype._destroy = function (er, cb) {
  this.invalidate()
  Transform.prototype._destroy.call(this, er, cb)
}