Skip to main content
Module

x/streamtools/collect.ts>collect

🦕 This is a Deno module that provides utilities for handling Streams API.
Latest
function collect
import { collect } from "https://deno.land/x/streamtools@v1.0.0/collect.ts";

Reads all chunks from a readable stream and returns them as an array of chunks.

import { collect } from "./collect.ts";

const reader = new ReadableStream<number>({
  start(controller) {
    controller.enqueue(1);
    controller.enqueue(2);
    controller.enqueue(3);
    controller.close();
  },
});

console.log(await collect(reader)); // [1, 2, 3]

Type Parameters

T

The type of the chunks to be read from the stream.

Parameters

stream: ReadableStream<T>

The readable stream to read chunks from.

optional
options: PipeOptions = [UNSUPPORTED]

Options for configuring the piping behavior.

Returns

Promise<T[]>

A promise that resolves with an array of all the chunks read from the stream.