mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
24 lines
508 B
TypeScript
24 lines
508 B
TypeScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
const textDecoder = new TextDecoder();
|
|
|
|
export async function toText(
|
|
readableStream: ReadableStream,
|
|
): Promise<string> {
|
|
const reader = readableStream.getReader();
|
|
let result = "";
|
|
|
|
while (true) {
|
|
const { done, value } = await reader.read();
|
|
|
|
if (done) {
|
|
break;
|
|
}
|
|
|
|
result += typeof value === "string" ? value : textDecoder.decode(value);
|
|
}
|
|
|
|
return result;
|
|
}
|