Skip to main content
Module

x/streamtools/mod.ts>readAll

🦕 This is a Deno module that provides utilities for handling Streams API.
Go to Latest
function readAll
import { readAll } from "https://deno.land/x/streamtools@v0.4.0/mod.ts";

Reads all available bytes from a given ReadableStream<Uint8Array> and concatenates them into a single Uint8Array.

import { assertEquals } from "https://deno.land/std@0.186.0/testing/asserts.ts";
import { readAll } from "./read_all.ts";

const encoder = new TextEncoder();
const stream = new ReadableStream({
  start(controller) {
    controller.enqueue(encoder.encode("Hello"));
    controller.enqueue(encoder.encode("World"));
    controller.close();
  },
});
const result = await readAll(stream);
assertEquals(result, encoder.encode("HelloWorld"));

Parameters

stream: ReadableStream<Uint8Array>

The stream to read from.

optional
options: PipeOptions = [UNSUPPORTED]

Options for configuring the piping behavior.

Returns

Promise<Uint8Array>

A promise that resolves to a Uint8Array containing all the bytes read from the stream.