pax_global_header00006660000000000000000000000064135446551240014523gustar00rootroot0000000000000052 comment=106097fbb7a09edf7c5f6f387ea2533fde4d0d47 pumpify-2.0.1/000077500000000000000000000000001354465512400132145ustar00rootroot00000000000000pumpify-2.0.1/.gitignore000066400000000000000000000000151354465512400152000ustar00rootroot00000000000000node_modules pumpify-2.0.1/.travis.yml000066400000000000000000000000731354465512400153250ustar00rootroot00000000000000language: node_js node_js: - '10' - '12' sudo: false pumpify-2.0.1/LICENSE000066400000000000000000000020661354465512400142250ustar00rootroot00000000000000The 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-2.0.1/README.md000066400000000000000000000035601354465512400144770ustar00rootroot00000000000000# 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-2.0.1/index.js000066400000000000000000000033361354465512400146660ustar00rootroot00000000000000var 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.message === 'premature close' ? null : err) ended = true // pump ends after the last stream is not writable *but* // pumpify still forwards the readable part so we need to catch errors // still, so reenable autoDestroy in this case if (self._autoDestroy === false) self._autoDestroy = true self.uncork() }) if (this.destroyed) return onclose() this.setWritable(w) this.setReadable(r) } return Pumpify } module.exports = define({autoDestroy:false, destroy:false}) module.exports.obj = define({autoDestroy: false, destroy:false, objectMode:true, highWaterMark:16}) module.exports.ctor = define pumpify-2.0.1/package.json000066400000000000000000000014141354465512400155020ustar00rootroot00000000000000{ "name": "pumpify", "version": "2.0.1", "description": "Combine an array of streams into a single duplex stream using pump and duplexify", "main": "index.js", "dependencies": { "duplexify": "^4.1.1", "inherits": "^2.0.3", "pump": "^3.0.0" }, "devDependencies": { "tape": "^4.10.2", "through2": "^3.0.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-2.0.1/test.js000066400000000000000000000110251354465512400145300ustar00rootroot00000000000000var tape = require('tape') var through = require('through2') var pumpify = require('./') var stream = require('stream') var duplexify = require('duplexify') 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) }) tape('preserves error', function (t) { var a = through() var b = through(function (data, enc, cb) { cb(new Error('stop')) }) var c = through() var s = pumpify() s.on('error', function (err) { t.same(err.message, 'stop') t.end() }) s.setPipeline(a, b, c) s.resume() s.write('hi') }) tape('preserves error again', function (t) { var ws = new stream.Writable() var rs = new stream.Readable({highWaterMark: 16}) ws._write = function (data, enc, cb) { cb(null) } var once = true rs._read = function () { process.nextTick(function () { if (!once) return once = false rs.push('hello world') }) } var pumpifyErr = pumpify( through(), through(function(chunk, _, cb) { cb(new Error('test')) }), ws ) rs.pipe(pumpifyErr) .on('error', function (err) { t.ok(err) t.ok(err.message !== 'premature close', 'does not close with premature close') t.end() }) }) tape('returns error from duplexify', function (t) { var a = through() var b = duplexify() var s = pumpify() s.setPipeline(a, b) s.on('error', function (err) { t.same(err.message, 'stop') t.end() }) s.write('data') // Test passes if `.end()` is not called s.end() b.setWritable(through()) setImmediate(function () { b.destroy(new Error('stop')) }) })