coyotte508's picture
coyotte508 HF staff
✨ Upload new photos & products, delete existing products
8a49743
raw
history blame
378 Bytes
import type { Readable } from 'stream';
/**
* Reads a binary stream in memory and store it in a buffer
*
* @param stream The readable stream to read
* @returns {Buffer}
*/
export async function streamToBuffer(stream: Readable): Promise<Buffer> {
const chunks: Buffer[] = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
return Buffer.concat(chunks);
}