Converts a ReadableSteam of strings or Uint8Arrays to a single string. Works the same as Response.text and Request.text, but also extends to support streams of strings.
A ReadableStream to convert into a string.
ReadableStream
string
A Promise that resolves to the string.
Promise
import { toText } from "@std/streams/to-text";import { assertEquals } from "@std/assert";const stream = ReadableStream.from(["Hello, ", "world!"]);assertEquals(await toText(stream), "Hello, world!"); Copy
import { toText } from "@std/streams/to-text";import { assertEquals } from "@std/assert";const stream = ReadableStream.from(["Hello, ", "world!"]);assertEquals(await toText(stream), "Hello, world!");
import { toText } from "@std/streams/to-text";import { assertEquals } from "@std/assert";const stream = ReadableStream.from(["Hello, ", "world!"]) .pipeThrough(new TextEncoderStream());assertEquals(await toText(stream), "Hello, world!"); Copy
import { toText } from "@std/streams/to-text";import { assertEquals } from "@std/assert";const stream = ReadableStream.from(["Hello, ", "world!"]) .pipeThrough(new TextEncoderStream());assertEquals(await toText(stream), "Hello, world!");
Converts a ReadableSteam of strings or Uint8Arrays to a single string. Works the same as Response.text and Request.text, but also extends to support streams of strings.