🌊 Reads a byte stream fully into a single Uint8Array.

Syntax

TypeScript
import { streamToBytes } from '@opentf/std';

streamToBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;

Parameters

NameTypeDescription
streamReadableStream<Uint8Array>The stream to drain.

Returns

A promise for the concatenated bytes. The chunks are joined in one allocation at the end rather than reallocated per chunk.

Examples

TypeScript
await streamToBytes(response.body) //=> Uint8Array [...]

Hashing a response body:

TypeScript
const bytes = await streamToBytes(response.body);
await sha256(bytesToString(bytes));
Last updated on
Edit this page