Initial Commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user