mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
22 lines
439 B
TypeScript
22 lines
439 B
TypeScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
export async function toBlob(
|
|
readableStream: ReadableStream,
|
|
): Promise<Blob> {
|
|
const reader = readableStream.getReader();
|
|
const chunks: Uint8Array[] = [];
|
|
|
|
while (true) {
|
|
const { done, value } = await reader.read();
|
|
|
|
if (done) {
|
|
break;
|
|
}
|
|
|
|
chunks.push(value);
|
|
}
|
|
|
|
return new Blob(chunks);
|
|
}
|