toBlob

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

function

async function toBlob(stream: ReadableStream<Uint8Array>): Promise<Blob>

Converts a ReadableStream of Uint8Arrays to a Blob. Works the same as Response.blob.

stream: ReadableStream<Uint8Array>

A ReadableStream of Uint8Arrays to convert into a Blob.

Returns

A Promise that resolves to the Blob.

Example: Basic usage

import { toBlob } from "@ende/streams/to-blob";
import { assertEquals } from "@ende/assert";

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

Source