File size: 378 Bytes
8a49743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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);
}