import type { Readable } from 'node:stream'; export const streamToBuffer = (stream: Readable): Promise => new Promise((resolve, reject) => { const chunks: Array = []; stream .on('data', (data) => chunks.push(data)) .on('end', () => resolve(Buffer.concat(chunks))) .on('error', (error) => reject(error)) // force stream to resume data flow in case it was explicitly paused before .resume(); });