Places.prototype.createReadStream = function (lat, lon, opts) { if (typeof lat == 'object') { opts = lon; lon = lat.longitude; lat = lat.latitude; } opts = opts || {}; var data = this.data; var search = this.trie.createSearchStream(encode(lat, lon), opts); var get = ordered(function (key, cb) { data.get(key, { valueEncoding: 'json' }, function (err, name) { if (err) { cb(err); } else if (!opts.position) { cb(null, name); } else { var hash = key.substring(0, 12); var position = decode(hash); cb(null, { name: name, position: { latitude: position.lat, longitude: position.lon } }); } }); }); var tr = throughout(search, get); tr.writable = false; return tr; };
function run (opts) { if (!opts) opts = {}; var input = through(); var browser = browserRun(opts); var dpl = throughout(input, browser); browser .pipe(finished(opts, function (results) { browser.stop(); dpl.emit('results', results); })); return dpl; }
function tmp () { var buf = []; var real; var input = through(function (chunk) { if (!real) { buf.push(chunk); return false; } else { return real.write(chunk); } }); var output = through(); var tr = throughout(input, output); tr.replace = function (stream) { if (!input.readable) return stream.end(); // already ended if (real) throw new Error('can replace only once'); real = stream; tr.readable = real.readable; tr.writable = real.writable; if (real.readable) real.pipe(output); if (real.writable) input.pipe(real); stream.on('error', function (err) { tr.emit('error', err); }); tr.on('end',function(){ stream.end(); }) for (var i = 0; i < buf.length; i++) real.write(buf[i]); buf = null; } return tr; }
test('a very large binary file piped into unbzip2-stream results in original file content', function(t) { t.plan(2); var source = fs.createReadStream('test/fixtures/vmlinux.bin.bz2'); var unbz2 = unbzip2Stream(); var received = 0; var buffers = []; unbz2.on('error', function(err) { console.log(err); //t.notOk(err.message); }); var sink = through( function write(data) { received += data.length; buffers.push(data); }, function end() { console.log('EMD'); var expected = fs.readFileSync('test/fixtures/vmlinux.bin'); t.equal(received, expected.length); t.deepEqual(Buffer.concat(buffers), expected); this.queue(null); }); source.pipe(throughout(unbz2,sink)); });