es-toolkit/tests/utils/streamToBuffer.ts
Dayong Lee 8600129813
style: Fix all lint errors (#351)
* Fix lint error

* Style format

* Add class, map, set
2024-08-07 18:50:42 +09:00

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));
});
});
}