mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 17:19:06 -05:00
42 lines
881 B
TypeScript
42 lines
881 B
TypeScript
// Copyright Node.js contributors. All rights reserved. MIT License.
|
|
import pl from "./pipeline.ts";
|
|
import type { PipelineArguments } from "./pipeline.ts";
|
|
import eos from "./end_of_stream.ts";
|
|
import type {
|
|
FinishedOptions,
|
|
StreamImplementations as FinishedStreams,
|
|
} from "./end_of_stream.ts";
|
|
|
|
export function pipeline(...streams: PipelineArguments) {
|
|
return new Promise((resolve, reject) => {
|
|
pl(
|
|
...streams,
|
|
(err, value) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(value);
|
|
}
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
export function finished(
|
|
stream: FinishedStreams,
|
|
opts?: FinishedOptions,
|
|
) {
|
|
return new Promise<void>((resolve, reject) => {
|
|
eos(
|
|
stream,
|
|
opts || null,
|
|
(err) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
}
|