14 lines
427 B
TypeScript
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);
|
|
}
|