filter (fn) { this.debug('Setting a filter for incoming traffic') if (typeof fn !== 'function') throw Error('filter() accepts only function!') this._filter = through2(fn) return this /* chainable method */ }
through2(function(kv, _, next){ var indexKey = mapFn(kv.key, kv.value, subset) if (indexKey != null && match(indexKey)) next(null, kv) else next() })
self.client.pipe(through2(function (chunk, enc, callback) { debug('Got incoming data ->', chunk) this.push(chunk) if (self._output) hexerIn.write(chunk) // hex Dump: incoming callback() })) .pipe(self._filter)
function getData(proxy) { return new Promise((resolve, reject) => { const options = { url: VPNGATE_API_URL }; if (proxy) resolveProxy(proxy, options); request(options) .on('response', (response) => { if (response.statusCode !== 200) reject(new Error(`Request failed with code ${response.statusCode}`)); }) .on('error', err => reject(networkError(err))) .pipe(through2(filter)) .pipe(csv()) .on('error', reject) .on('end_parsed', resolve); }); }
// TODO: empty before? // TODO: use batched writestream // TODO: emit warning if pre hook is called during rebuild this.parent.createReadStream().pipe(through2(function(kv, _, next){ var ops = [], add = ops.push.bind(ops) index.update(kv.key, kv.value, add) return ops.length ? index.db.batch(ops, next) : next() })).on('finish', done).on('error', done)
constructor (opts) { super() opts = opts || {} this.debug = debug this._protocol = opts.protocol || 'tcp' this._waitTime = opts.waitTime || null this._destination = opts.destination || '127.0.0.1' this._loopback = opts.loopback || false this._encoding = opts.encoding || null this._unixSocket = opts.unixSocket || null this._port = opts.port || null this._output = opts.output || null this._exec = opts.exec || null this._filter = opts.filter || through2() // passThrough }
function streamDebug (debug, IPandPort) { var self = this return through2(function (chunk, enc, cb) { debug('Got data from', IPandPort, '->', chunk) if (self._output) hexerIn.write(chunk) // hex Dump this.push(chunk) cb() }) }
this.inputStream.pipe(this.sEncrypt) .pipe(base64.encode()) .pipe(new Batch({size: 76, strictMode: false})) .pipe(through2(function (chunk, enc, next) { this.push(chunk + os.EOL) // new line every 76 chars next() }))
through2(function(key, _, next){ db.get(key, function(err, entity){ if (err) return next() if (values) return next(null, entity) if (keys) return next(null, key) next(null, {key: key, value: entity}) }) })
formats.forEach(function (format) { test(format, function (t) { t.plan(5) let sawNumbers = false fs.createReadStream(base + format) .pipe(tabular({ keys: snake })) .pipe(through2(function (obj, _, next) { sawNumbers = numstr(obj) next(null, obj) })) .pipe(concat(function (data) { t.ok(sawNumbers, 'saw numbers') t.equal(data.length, expected.length, 'length ok') t.deepEqual(data[data.length - 1], expected[expected.length - 1], 'last row ok') t.deepEqual(data[0], expected[0], 'first row ok') t.ok(deepEqual(data, expected), 'deep equal') })) }) })
function updateIndex(index, done) { var h = HyperLogLog(12) // Standard error is 1.625% var length = 0 // Approximate number of total rows function end(err) { if (err) debug(err) done && done() done = null } index.createKeyStream().pipe(through2(function(key, _, next){ h.add(sigmund(key.slice(0,-1))) length++ next() })).on('end', function() { // TODO: maybe save all stats in one place index.saveStatistics({ cardinality: h.count(), length: length }, end) }).on('error', end) }
stream.pipe(through2(function(kv, _, next){ next(null, values ? kv.value : kv.key) }))
.pipe(through2((data, enc, next) => { try {
through2(function(tuple, _, next){ if (typeof tuple !== 'object') return next() if (kv == null) kv = 'key' in tuple && 'value' in tuple if (kv) tuple.value = select(tuple.value, selector) else tuple = select(tuple, selector) next(null, tuple) })
through2(function(kv, _, next){ for(var i=0, l=filters.length; i<l; i++) if (!filters[i](kv.key, kv.value)) return next() next(null, kv) })