mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-11 08:54:07 +03:00
8600129813
* Fix lint error * Style format * Add class, map, set
20 lines
405 B
TypeScript
20 lines
405 B
TypeScript
import { Readable } from 'node:stream';
|
|
|
|
export async function streamToBuffer(stream: Readable) {
|
|
return await new Promise<Buffer>((resolve, reject) => {
|
|
const chunks: Buffer[] = [];
|
|
|
|
stream.on(`error`, error => {
|
|
reject(error);
|
|
});
|
|
|
|
stream.on(`data`, chunk => {
|
|
chunks.push(chunk);
|
|
});
|
|
|
|
stream.on(`end`, () => {
|
|
resolve(Buffer.concat(chunks));
|
|
});
|
|
});
|
|
}
|