mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
9c3c53e65b
This commit improves docs of the streams module. Towards #3764 --------- Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
29 lines
863 B
TypeScript
29 lines
863 B
TypeScript
// 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();
|
|
}
|