Function toBlob

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

    Parameters

    • stream: ReadableStream<Uint8Array>

      A ReadableStream of Uint8Arrays to convert into a Blob.

    Returns Promise<Blob>

    A Promise that resolves to the Blob.

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

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