toBytes

import { toBytes } from "jsr:@ende/streams";

function

function toBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>

Converts a ReadableStream of Uint8Arrays to a Uint8Array. Works the same as Response.bytes.

stream: ReadableStream<Uint8Array>

A ReadableStream of Uint8Arrays to convert into a Uint8Array.

Returns

A Promise that resolves to the Uint8Array.

Example: Basic usage

import { toBytes } from "@ende/streams/to-bytes";
import { assertEquals } from "@ende/assert";

const stream = ReadableStream.from([
  new Uint8Array([1, 2]),
  new Uint8Array([3, 4, 5]),
]);
const bytes = await toBytes(stream);
assertEquals(bytes, new Uint8Array([1, 2, 3, 4, 5]));

Source