2020-06-28 16:29:01 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const {
|
2021-02-13 23:15:23 +08:00
|
|
|
ArrayPrototypePop,
|
2020-06-28 16:29:01 +08:00
|
|
|
Promise,
|
|
|
|
} = primordials;
|
|
|
|
|
2021-02-25 03:30:50 +08:00
|
|
|
const {
|
|
|
|
isIterable,
|
2021-07-07 17:33:55 +08:00
|
|
|
isNodeStream,
|
2023-02-03 03:45:42 +08:00
|
|
|
isWebStream,
|
2021-02-25 03:30:50 +08:00
|
|
|
} = require('internal/streams/utils');
|
|
|
|
|
2021-06-18 04:25:34 +08:00
|
|
|
const { pipelineImpl: pl } = require('internal/streams/pipeline');
|
2022-01-30 22:07:32 +08:00
|
|
|
const { finished } = require('internal/streams/end-of-stream');
|
2020-06-28 16:29:01 +08:00
|
|
|
|
2023-01-20 20:37:52 +08:00
|
|
|
require('stream');
|
|
|
|
|
2020-06-28 16:29:01 +08:00
|
|
|
function pipeline(...streams) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2021-02-13 23:15:23 +08:00
|
|
|
let signal;
|
2021-11-20 02:14:32 +08:00
|
|
|
let end;
|
2021-02-13 23:15:23 +08:00
|
|
|
const lastArg = streams[streams.length - 1];
|
|
|
|
if (lastArg && typeof lastArg === 'object' &&
|
2023-02-03 03:45:42 +08:00
|
|
|
!isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg)) {
|
2021-02-13 23:15:23 +08:00
|
|
|
const options = ArrayPrototypePop(streams);
|
|
|
|
signal = options.signal;
|
2021-11-20 02:14:32 +08:00
|
|
|
end = options.end;
|
2021-02-13 23:15:23 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 04:25:34 +08:00
|
|
|
pl(streams, (err, value) => {
|
2020-06-28 16:29:01 +08:00
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve(value);
|
|
|
|
}
|
2021-11-20 02:14:32 +08:00
|
|
|
}, { signal, end });
|
2020-06-28 16:29:01 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
finished,
|
|
|
|
pipeline,
|
|
|
|
};
|