UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

47 lines (41 loc) 1.07 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/stream/promises.js import { isIterable, isNodeStream, isWebStream, } from "nstdlib/lib/internal/streams/utils"; import { pipelineImpl as pl } from "nstdlib/lib/internal/streams/pipeline"; import { finished } from "nstdlib/lib/internal/streams/end-of-stream"; import * as __hoisted_stream__ from "nstdlib/stub/stream"; __hoisted_stream__; function pipeline(...streams) { return new Promise((resolve, reject) => { let signal; let end; const lastArg = streams[streams.length - 1]; if ( lastArg && typeof lastArg === "object" && !isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg) ) { const options = Array.prototype.pop.call(streams); signal = options.signal; end = options.end; } pl( streams, (err, value) => { if (err) { reject(err); } else { resolve(value); } }, { signal, end }, ); }); } export { finished }; export { pipeline };