| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/gavin/workspace/happymandarin/node_modules/multipipe/ |
Upload File : |
/**
* Module dependencies.
*/
var duplexer = require('duplexer2');
var Stream = require('stream');
/**
* Slice reference.
*/
var slice = [].slice;
/**
* Duplexer options.
*/
var opts = {
bubbleErrors: false
};
/**
* Expose `pipe`.
*/
module.exports = pipe;
/**
* Pipe.
*
* @param {Stream,...,[Function]}
* @return {Stream}
* @api public
*/
function pipe(){
if (arguments.length == 1) return arguments[0];
var streams = slice.call(arguments);
var cb;
if ('function' == typeof streams[streams.length - 1]) {
cb = streams.splice(-1)[0];
}
var first = streams[0];
var last = streams[streams.length - 1];
var ret;
if (first.writable && last.readable) ret = duplexer(opts, first, last);
else if (first.writable) ret = first;
else if (last.readable) ret = last;
else ret = new Stream;
streams.forEach(function(stream, i){
var next = streams[i+1];
if (next) stream.pipe(next);
if (stream != ret) stream.on('error', ret.emit.bind(ret, 'error'));
});
if (cb) {
var ended = false;
ret.on('error', end);
last.on('finish', end);
function end(err){
if (ended) return;
ended = true;
cb(err);
}
}
return ret;
}