import { u8 } from '@fuman/utils'

export async function streamToBuffer(stream: ReadableStream<Uint8Array>): Promise<Uint8Array> {
    const chunks: Uint8Array[] = []

    const reader = stream.getReader()

    while (true) {
        const { done, value } = await reader.read()
        if (done) break
        chunks.push(value)
    }

    return u8.concat(chunks)
}
