• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const {
4  ArrayPrototypePop,
5  Promise,
6} = primordials;
7
8const {
9  isIterable,
10  isNodeStream,
11  isWebStream,
12} = require('internal/streams/utils');
13
14const { pipelineImpl: pl } = require('internal/streams/pipeline');
15const { finished } = require('internal/streams/end-of-stream');
16
17require('stream');
18
19function pipeline(...streams) {
20  return new Promise((resolve, reject) => {
21    let signal;
22    let end;
23    const lastArg = streams[streams.length - 1];
24    if (lastArg && typeof lastArg === 'object' &&
25        !isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg)) {
26      const options = ArrayPrototypePop(streams);
27      signal = options.signal;
28      end = options.end;
29    }
30
31    pl(streams, (err, value) => {
32      if (err) {
33        reject(err);
34      } else {
35        resolve(value);
36      }
37    }, { signal, end });
38  });
39}
40
41module.exports = {
42  finished,
43  pipeline,
44};
45