Alexandre Bodin 2d12f88394 Optimize file
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-03-09 09:05:43 +01:00

24 lines
472 B
JavaScript

'use strict';
/**
* Utils file containing file treatment utils
*/
const bytesToKbytes = bytes => Math.round((bytes / 1000) * 100) / 100;
const streamToBuffer = stream =>
new Promise((resolve, reject) => {
const chunks = [];
stream.on('data', chunk => {
chunks.push(chunk);
});
stream.on('end', () => {
resolve(Buffer.concat(chunks));
});
stream.on('error', reject);
});
module.exports = {
streamToBuffer,
bytesToKbytes,
};