@foal/core
Version:
Full-featured Node.js framework, with no complexity
19 lines (18 loc) • 590 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.streamToBuffer = streamToBuffer;
/**
* Converts a stream of buffers into a buffer.
*
* @export
* @param {NodeJS.ReadableStream} stream - A readable stream.
* @returns {Promise<Buffer>} The concatenated buffer
*/
async function streamToBuffer(stream) {
return await new Promise((resolve, reject) => {
const chunks = [];
stream.on('data', (chunk) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks)));
});
}