🌊 Reads a stream fully into an array of its chunks.
Works on a stream of any chunk type, so it is the general form of streamToText and streamToBytes.
Syntax
TypeScript
import { streamToArray } from '@opentf/std'; streamToArray<T>(stream: ReadableStream<T>): Promise<T[]>;
Parameters
| Name | Type | Description |
|---|---|---|
| stream | ReadableStream<T> | The stream to drain. |
Returns
A promise for the chunks, in order.
Examples
TypeScript
await streamToArray(stream) //=> ['a', 'b', 'c'] await streamToArray(objectStream) //=> [{ a: 1 }, { b: 2 }]