aboutsummaryrefslogtreecommitdiff
path: root/src/js/node/stream.consumers.js
blob: a1f85ab943542cc3944e45c01f8e68d7e4a9b1d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Hardcoded module "node:stream/consumers" / "readable-stream/consumer"
const { Bun } = globalThis[Symbol.for("Bun.lazy")]("primordials");

export const arrayBuffer = Bun.readableStreamToArrayBuffer;
export const text = Bun.readableStreamToText;
export const json = stream => Bun.readableStreamToText(stream).then(JSON.parse);

export const buffer = async readableStream => {
  return new Buffer(await arrayBuffer(readableStream));
};

export const blob = Bun.readableStreamToBlob;

export default {
  [Symbol.for("CommonJS")]: 0,
  arrayBuffer,
  text,
  json,
  buffer,
  blob,
};