react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / stream-combiner2 / node_modules / through2 / through2.js
80555 viewsvar Transform = require('readable-stream/transform')1, inherits = require('util').inherits2, xtend = require('xtend')345// a noop _transform function6function noop (chunk, enc, callback) {7callback(null, chunk)8}91011// create a new export function, used by both the main export and12// the .ctor export, contains common logic for dealing with arguments13function through2 (construct) {14return function (options, transform, flush) {15if (typeof options == 'function') {16flush = transform17transform = options18options = {}19}2021if (typeof transform != 'function')22transform = noop2324if (typeof flush != 'function')25flush = null2627return construct(options, transform, flush)28}29}303132// main export, just make me a transform stream!33module.exports = through2(function (options, transform, flush) {34var t2 = new Transform(options)3536t2._transform = transform3738if (flush)39t2._flush = flush4041return t242})434445// make me a reusable prototype that I can `new`, or implicitly `new`46// with a constructor call47module.exports.ctor = through2(function (options, transform, flush) {48function Through2 (override) {49if (!(this instanceof Through2))50return new Through2(override)5152this.options = xtend(options, override)5354Transform.call(this, this.options)55}5657inherits(Through2, Transform)5859Through2.prototype._transform = transform6061if (flush)62Through2.prototype._flush = flush6364return Through265})666768module.exports.obj = through2(function (options, transform, flush) {69var t2 = new Transform(xtend({ objectMode: true, highWaterMark: 16 }, options))7071t2._transform = transform7273if (flush)74t2._flush = flush7576return t277})787980