Urara-Blog/node_modules/.pnpm-store/v3/files/85/24ae1659d8678302238c7b966f877ea545beee9c2de8837c6a370a3c86312be6e319cf274699ea1f9acf5f40ae26bab448086d566e44daecce8bcaaf5eea19
2022-08-14 01:14:53 +08:00

41 lines
885 B
Text

'use strict';
const { PassThrough } = require('stream');
module.exports = function (/*streams...*/) {
var sources = []
var output = new PassThrough({objectMode: true})
output.setMaxListeners(0)
output.add = add
output.isEmpty = isEmpty
output.on('unpipe', remove)
Array.prototype.slice.call(arguments).forEach(add)
return output
function add (source) {
if (Array.isArray(source)) {
source.forEach(add)
return this
}
sources.push(source);
source.once('end', remove.bind(null, source))
source.once('error', output.emit.bind(output, 'error'))
source.pipe(output, {end: false})
return this
}
function isEmpty () {
return sources.length == 0;
}
function remove (source) {
sources = sources.filter(function (it) { return it !== source })
if (!sources.length && output.readable) { output.end() }
}
}