pax_global_header00006660000000000000000000000064127277240400014517gustar00rootroot0000000000000052 comment=b3eb78d20b310409beca86de87a4fba68bc9656e pumpify-1.3.5/000077500000000000000000000000001272772404000132165ustar00rootroot00000000000000pumpify-1.3.5/.gitignore000066400000000000000000000000151272772404000152020ustar00rootroot00000000000000node_modules pumpify-1.3.5/.travis.yml000066400000000000000000000001041272772404000153220ustar00rootroot00000000000000language: node_js node_js: - "0.10" - "4" - "5" sudo: false pumpify-1.3.5/LICENSE000066400000000000000000000020661272772404000142270ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Mathias Buus 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.pumpify-1.3.5/README.md000066400000000000000000000035601272772404000145010ustar00rootroot00000000000000# pumpify Combine an array of streams into a single duplex stream using [pump](https://github.com/mafintosh/pump) and [duplexify](https://github.com/mafintosh/duplexify). If one of the streams closes/errors all streams in the pipeline will be destroyed. ``` npm install pumpify ``` [![build status](http://img.shields.io/travis/mafintosh/pumpify.svg?style=flat)](http://travis-ci.org/mafintosh/pumpify) ## Usage Pass the streams you want to pipe together to pumpify `pipeline = pumpify(s1, s2, s3, ...)`. `pipeline` is a duplex stream that writes to the first streams and reads from the last one. Streams are piped together using [pump](https://github.com/mafintosh/pump) so if one of them closes all streams will be destroyed. ``` js var pumpify = require('pumpify') var tar = require('tar-fs') var zlib = require('zlib') var fs = require('fs') var untar = pumpify(zlib.createGunzip(), tar.extract('output-folder')) // you can also pass an array instead // var untar = pumpify([zlib.createGunzip(), tar.extract('output-folder')]) fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar) ``` If you are pumping object streams together use `pipeline = pumpify.obj(s1, s2, ...)`. Call `pipeline.destroy()` to destroy the pipeline (including the streams passed to pumpify). ### Using `setPipeline(s1, s2, ...)` Similar to [duplexify](https://github.com/mafintosh/duplexify) you can also define the pipeline asynchronously using `setPipeline(s1, s2, ...)` ``` js var untar = pumpify() setTimeout(function() { // will start draining the input now untar.setPipeline(zlib.createGunzip(), tar.extract('output-folder')) }, 1000) fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar) ``` ## License MIT ## Related `pumpify` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one. pumpify-1.3.5/index.js000066400000000000000000000025561272772404000146730ustar00rootroot00000000000000var pump = require('pump') var inherits = require('inherits') var Duplexify = require('duplexify') var toArray = function(args) { if (!args.length) return [] return Array.isArray(args[0]) ? args[0] : Array.prototype.slice.call(args) } var define = function(opts) { var Pumpify = function() { var streams = toArray(arguments) if (!(this instanceof Pumpify)) return new Pumpify(streams) Duplexify.call(this, null, null, opts) if (streams.length) this.setPipeline(streams) } inherits(Pumpify, Duplexify) Pumpify.prototype.setPipeline = function() { var streams = toArray(arguments) var self = this var ended = false var w = streams[0] var r = streams[streams.length-1] r = r.readable ? r : null w = w.writable ? w : null var onclose = function() { streams[0].emit('error', new Error('stream was destroyed')) } this.on('close', onclose) this.on('prefinish', function() { if (!ended) self.cork() }) pump(streams, function(err) { self.removeListener('close', onclose) if (err) return self.destroy(err) ended = true self.uncork() }) if (this.destroyed) return onclose() this.setWritable(w) this.setReadable(r) } return Pumpify } module.exports = define({destroy:false}) module.exports.obj = define({destroy:false, objectMode:true, highWaterMark:16}) pumpify-1.3.5/package.json000066400000000000000000000014141272772404000155040ustar00rootroot00000000000000{ "name": "pumpify", "version": "1.3.5", "description": "Combine an array of streams into a single duplex stream using pump and duplexify", "main": "index.js", "dependencies": { "duplexify": "^3.1.2", "inherits": "^2.0.1", "pump": "^1.0.0" }, "devDependencies": { "tape": "^2.13.3", "through2": "^0.5.1" }, "scripts": { "test": "tape test.js" }, "repository": { "type": "git", "url": "git://github.com/mafintosh/pumpify" }, "keywords": [ "pump", "duplexify", "duplex", "streams", "stream", "pipeline", "combine" ], "author": "Mathias Buus", "license": "MIT", "bugs": { "url": "https://github.com/mafintosh/pumpify/issues" }, "homepage": "https://github.com/mafintosh/pumpify" } pumpify-1.3.5/test.js000066400000000000000000000062221272772404000145350ustar00rootroot00000000000000var tape = require('tape') var through = require('through2') var pumpify = require('./') var stream = require('stream') tape('basic', function(t) { t.plan(3) var pipeline = pumpify( through(function(data, enc, cb) { t.same(data.toString(), 'hello') cb(null, data.toString().toUpperCase()) }), through(function(data, enc, cb) { t.same(data.toString(), 'HELLO') cb(null, data.toString().toLowerCase()) }) ) pipeline.write('hello') pipeline.on('data', function(data) { t.same(data.toString(), 'hello') t.end() }) }) tape('3 times', function(t) { t.plan(4) var pipeline = pumpify( through(function(data, enc, cb) { t.same(data.toString(), 'hello') cb(null, data.toString().toUpperCase()) }), through(function(data, enc, cb) { t.same(data.toString(), 'HELLO') cb(null, data.toString().toLowerCase()) }), through(function(data, enc, cb) { t.same(data.toString(), 'hello') cb(null, data.toString().toUpperCase()) }) ) pipeline.write('hello') pipeline.on('data', function(data) { t.same(data.toString(), 'HELLO') t.end() }) }) tape('destroy', function(t) { var test = through() test.destroy = function() { t.ok(true) t.end() } var pipeline = pumpify(through(), test) pipeline.destroy() }) tape('close', function(t) { var test = through() var pipeline = pumpify(through(), test) pipeline.on('error', function(err) { t.same(err.message, 'lol') t.end() }) test.emit('error', new Error('lol')) }) tape('end waits for last one', function(t) { var ran = false var a = through() var b = through() var c = through(function(data, enc, cb) { setTimeout(function() { ran = true cb() }, 100) }) var pipeline = pumpify(a, b, c) pipeline.write('foo') pipeline.end(function() { t.ok(ran) t.end() }) t.ok(!ran) }) tape('always wait for finish', function(t) { var a = new stream.Readable() a._read = function() {} a.push('hello') var pipeline = pumpify(a, through(), through()) var ran = false pipeline.on('finish', function() { t.ok(ran) t.end() }) setTimeout(function() { ran = true a.push(null) }, 100) }) tape('async', function(t) { var pipeline = pumpify() t.plan(4) pipeline.write('hello') pipeline.on('data', function(data) { t.same(data.toString(), 'HELLO') t.end() }) setTimeout(function() { pipeline.setPipeline( through(function(data, enc, cb) { t.same(data.toString(), 'hello') cb(null, data.toString().toUpperCase()) }), through(function(data, enc, cb) { t.same(data.toString(), 'HELLO') cb(null, data.toString().toLowerCase()) }), through(function(data, enc, cb) { t.same(data.toString(), 'hello') cb(null, data.toString().toUpperCase()) }) ) }, 100) }) tape('early destroy', function(t) { var a = through() var b = through() var c = through() b.destroy = function() { t.ok(true) t.end() } var pipeline = pumpify() pipeline.destroy() setTimeout(function() { pipeline.setPipeline(a, b, c) }, 100) })