0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-30 09:08:00 -04:00
denoland-deno/std/node/_stream/promises.ts

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();
}
},
);
});
}