pax_global_header00006660000000000000000000000064126103012220014477gustar00rootroot0000000000000052 comment=1943d22459c54b1f65753e08f0bfb2dfb95f114b stream-combiner2-1.1.1/000077500000000000000000000000001261030122200146505ustar00rootroot00000000000000stream-combiner2-1.1.1/.gitignore000066400000000000000000000000521261030122200166350ustar00rootroot00000000000000node_modules node_modules/* npm_debug.log stream-combiner2-1.1.1/.travis.yml000066400000000000000000000000731261030122200167610ustar00rootroot00000000000000language: node_js node_js: - 0.8 - 0.10 - 0.12 - 4 stream-combiner2-1.1.1/LICENSE000066400000000000000000000020611261030122200156540ustar00rootroot00000000000000Copyright (c) 2012 'Dominic Tarr' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. stream-combiner2-1.1.1/README.md000066400000000000000000000020311261030122200161230ustar00rootroot00000000000000# stream-combiner2 This is a sequel to [stream-combiner](https://npmjs.org/package/stream-combiner) for streams3. ``` js var combine = require('stream-combiner2') ``` ## Combine (stream1,...,streamN) Turn a pipeline into a single stream. `Combine` returns a stream that writes to the first stream and reads from the last stream. Streams1 streams are automatically upgraded to be streams3 streams. Listening for 'error' will recieve errors from all streams inside the pipe. ```js var Combine = require('stream-combiner') var es = require('event-stream') Combine( // connect streams together with `pipe` process.openStdin(), // open stdin es.split(), // split stream to break on newlines es.map(function (data, callback) { // turn this async function into a stream var repr = inspect(JSON.parse(data)) // render it nicely callback(null, repr) }), process.stdout // pipe it to stdout ! ) ``` ## License MIT stream-combiner2-1.1.1/index.js000066400000000000000000000031271261030122200163200ustar00rootroot00000000000000var PassThrough = require('readable-stream').PassThrough var Readable = require('readable-stream').Readable var duplexer = require('duplexer2') module.exports = function () { var streams if(arguments.length == 1 && Array.isArray(arguments[0])) { streams = arguments[0] } else { streams = [].slice.call(arguments) } return combine(streams) } module.exports.obj = function () { var streams if(arguments.length == 1 && Array.isArray(arguments[0])) { streams = arguments[0] } else { streams = [].slice.call(arguments) } return combine(streams, { objectMode: true }) } function combine (streams, opts) { for (var i = 0; i < streams.length; i++) streams[i] = wrap(streams[i], opts) if(streams.length == 0) return new PassThrough(opts) else if(streams.length == 1) return streams[0] var first = streams[0] , last = streams[streams.length - 1] , thepipe = duplexer(opts, first, last) //pipe all the streams together function recurse (streams) { if(streams.length < 2) return streams[0].pipe(streams[1]) recurse(streams.slice(1)) } recurse(streams) function onerror () { var args = [].slice.call(arguments) args.unshift('error') thepipe.emit.apply(thepipe, args) } //es.duplex already reemits the error from the first and last stream. //add a listener for the inner streams in the pipeline. for(var i = 1; i < streams.length - 1; i ++) streams[i].on('error', onerror) return thepipe } function wrap (tr, opts) { if (typeof tr.read === 'function') return tr return new Readable(opts).wrap(tr) } stream-combiner2-1.1.1/package.json000066400000000000000000000011131261030122200171320ustar00rootroot00000000000000{ "name": "stream-combiner2", "version": "1.1.1", "homepage": "https://github.com/substack/stream-combiner2", "repository": { "type": "git", "url": "git://github.com/substack/stream-combiner2.git" }, "dependencies": { "duplexer2": "~0.1.0", "readable-stream": "^2.0.2" }, "devDependencies": { "tape": "~2.3.0", "through2": "^2.0.0", "event-stream": "~3.0.7" }, "scripts": { "test": "set -e; for t in test/*.js; do node $t; done" }, "author": "'Dominic Tarr' (http://dominictarr.com)", "license": "MIT" } stream-combiner2-1.1.1/test/000077500000000000000000000000001261030122200156275ustar00rootroot00000000000000stream-combiner2-1.1.1/test/index.js000066400000000000000000000037241261030122200173020ustar00rootroot00000000000000var es = require('event-stream') var through = require('through2') var combine = require('..') var test = require('tape') test('re-emit error object for old streams', function (test) { test.plan(1) var expectedErr = new Error('asplode') var pipe = combine( es.through(function(data) { return this.emit('error', expectedErr) }) ) pipe.on('error', function (err) { test.equal(err, expectedErr) }) pipe.write('pow') }) test('do not duplicate errors', function (test) { var errors = 0; var pipe = combine( es.through(function(data) { return this.emit('data', data); }), es.through(function(data) { return this.emit('error', new Error(data)); }) ) pipe.on('error', function(err) { errors++ test.ok(errors, 'expected error count') process.nextTick(function () { return test.end(); }) }) return pipe.write('meh'); }) test('3 pipe do not duplicate errors', function (test) { var errors = 0; var pipe = combine( es.through(function(data) { return this.emit('data', data); }), es.through(function(data) { return this.emit('error', new Error(data)); }), es.through() ) pipe.on('error', function(err) { errors++ test.ok(errors, 'expected error count') process.nextTick(function () { return test.end(); }) }) return pipe.write('meh'); }) test('0 argument through stream', function (test) { test.plan(3) var pipe = combine() , expected = [ 'beep', 'boop', 'robots' ] pipe.pipe(es.through(function(data) { test.equal(data.toString('utf8'), expected.shift()) })) pipe.write('beep') pipe.write('boop') pipe.end('robots') }) test('object mode', function (test) { test.plan(2) var pipe = combine.obj() , expected = [ [4,5,6], {x:5} ] pipe.pipe(through.obj(function(data, enc, next) { test.deepEqual(data, expected.shift()) next() })) pipe.write([4,5,6]) pipe.write({x:5}) pipe.end() })