// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:stream/consumers
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.

import * as consumers from "node:stream/consumers";
import { Readable } from "node:stream";

try {
  console.log("consumers.text:", await consumers.text(Readable.from(["he", "llo"])));
} catch (e) {
  console.log("text ERROR:", (e as Error).message);
}

try {
  console.log("consumers.json:", await consumers.json(Readable.from(['{"a":', '1}'])));
} catch (e) {
  console.log("json ERROR:", (e as Error).message);
}

try {
  const buf = await consumers.buffer(Readable.from([Buffer.from("ab"), Buffer.from("cd")]));
  console.log("consumers.buffer hex:", buf.toString("hex"));
} catch (e) {
  console.log("buffer ERROR:", (e as Error).message);
}

try {
  const ab = await consumers.arrayBuffer(Readable.from([Buffer.from("xy")]));
  console.log("arrayBuffer byteLength:", ab.byteLength);
  console.log("arrayBuffer first byte:", new Uint8Array(ab)[0]);
} catch (e) {
  console.log("arrayBuffer ERROR:", (e as Error).message);
}

try {
  const bytes = await consumers.bytes(Readable.from([Buffer.from("zz")]));
  console.log("bytes length:", bytes.length);
  console.log("bytes[0]:", bytes[0]);
} catch (e) {
  console.log("bytes ERROR:", (e as Error).message);
}

try {
  const blob = await consumers.blob(Readable.from([Buffer.from("blob")]));
  console.log("blob.size:", blob.size);
  console.log("blob.text:", await blob.text());
} catch (e) {
  console.log("blob ERROR:", (e as Error).message);
}
