toArrayBuffer

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

function

async function toArrayBuffer(readableStream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>

Converts a ReadableStream of Uint8Arrays to an ArrayBuffer. Works the same as Response.arrayBuffer.

readableStream: ReadableStream<Uint8Array>

A ReadableStream of Uint8Arrays to convert into an ArrayBuffer.

Returns

A promise that resolves with the ArrayBuffer containing all the data from the stream.

Example: Basic usage

import { toArrayBuffer } from "@ende/streams/to-array-buffer";
import { assertEquals } from "@ende/assert";

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

Source