Function toText

  • 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.

    Parameters

    • stream: ReadableStream<Uint8Array> | ReadableStream<string>

      A ReadableStream to convert into a string.

    Returns Promise<string>

    A Promise that resolves to the string.

    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!");