Files
suaveplan/packages/foundation/flow/streams/src/utils/stream/process-data-stream/process-data-stream.ts
2026-05-27 23:47:53 +01:00

14 lines
427 B
TypeScript

import { streamToUint8Array } from "../round-trip/round-trip.js";
/**
* Drains `stream` into a `Uint8Array` and feeds it to `processor`. Returns
* the processor's resolved value.
*/
export async function processDataStream<T>(
stream: ReadableStream<Uint8Array>,
processor: (data: Uint8Array) => T | Promise<T>
): Promise<T> {
const bytes = await streamToUint8Array(stream);
return await processor(bytes);
}