summaryrefslogtreecommitdiff
path: root/std/node/_stream/promises.ts
blob: 1adf4ea3f5b592b60b3a4083701e67c0503da943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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();
        }
      },
    );
  });
}