// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Converts a {@linkcode ReadableStream} of {@linkcode Uint8Array}s to a
 * {@linkcode Blob}. Works the same as {@linkcode Response.blob}.
 *
 * @param stream A `ReadableStream` of `Uint8Array`s to convert into a `Blob`.
 * @returns A `Promise` that resolves to the `Blob`.
 *
 * @example Basic usage
 * ```ts
 * import { toBlob } from "@std/streams/to-blob";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const stream = ReadableStream.from([
 *   new Uint8Array([1, 2]),
 *   new Uint8Array([3, 4, 5]),
 * ]);
 * const blob = await toBlob(stream);
 * assertEquals(blob.size, 5);
 * ```
 */
export async function toBlob(
  stream: ReadableStream<Uint8Array>,
): Promise<Blob> {
  return await new Response(stream).blob();
}

// denoCacheMetadata={"headers":{"x-jsr-backend":"modules","x-robots-tag":"noindex","cf-cache-status":"HIT","accept-ranges":"bytes","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-length":"863","access-control-allow-origin":"*","cache-control":"public, max-age=31536000, immutable","etag":"\"046fa53419dac4323b6227787dd22833\"","age":"112265","server":"cloudflare","access-control-expose-headers":"*","x-content-type-options":"nosniff","set-cookie":"__cf_bm=TVTij76ZScaQDtqIIdbcMb2.0A1OwnVAsAqvASJjQh0-1785241875.183065-1.0.1.1-1VtsFyzlBLfUfz4Sz1Z3x_I38Z2JKAaJPJq6Q.nP6UxK__m_m10PWFjcxkw.G5LNJnVgEawBd1dVxyMzidjOu0x6sY0s7ibmK2wB_cikm3bfcUtOSATE.Zz0SQyC0qkF; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=r3BRUi%2BkH5sdaWCmXYW2ip7eivzMUs1c2szEHVZ6y2IJbA9yDb26mLd2z4a14Kc9ugpOhwhHh6OLFbASk5YYTQqtjwTPg1ipcle02s4iYt62ltCnyOg0GxI%3D\"}]}","content-type":"text/typescript","alt-svc":"h3=\":443\"; ma=86400","cf-ray":"a223e657dacd7db6-LAX","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","vary":"Origin","cross-origin-resource-policy":"cross-origin"},"url":"https://jsr.io/@std/streams/0.224.5/to_blob.ts","time":1785241875}