speed lol

This commit is contained in:
Flummi 2018-09-03 21:31:36 +02:00
parent 37fc886839
commit 75a700e332
2 changed files with 7 additions and 2 deletions

View File

@ -2,5 +2,7 @@ const formatSize = (size, i = ~~(Math.log(size) / Math.log(1024))) => (size / Ma
const getUUID = () => Math.random().toString(36).slice(-10) + (new Date()).getTime().toString(36).slice(-3); const getUUID = () => Math.random().toString(36).slice(-10) + (new Date()).getTime().toString(36).slice(-3);
const calcSpeed = (bytes, seconds) => `${Math.round((bytes * 8 / seconds / 1000000) * 10000) / 10000} Mbit/s`;
export { formatSize, getUUID };
export { calcSpeed, formatSize, getUUID };

View File

@ -72,6 +72,7 @@ export default bot => {
const uuid = lib.getUUID(); const uuid = lib.getUUID();
const file = `${b}/${uuid}.${data.format[0].ext}`; const file = `${b}/${uuid}.${data.format[0].ext}`;
const dest = fs.createWriteStream(file); const dest = fs.createWriteStream(file);
const start = new Date();
res.body.pipe(dest); res.body.pipe(dest);
let t; let t;
dest.on("open", () => { dest.on("open", () => {
@ -95,7 +96,9 @@ export default bot => {
dest.on("close", blah => { dest.on("close", blah => {
if(t) { if(t) {
clearInterval(t); clearInterval(t);
e.reply(`gef0ckt lol: ${data.file} -> ${uuid}.${data.format[0].ext}, ~${lib.formatSize(fs.statSync(file).size)}`); const size = fs.statSync(file).size;
const time = ~~((new Date() - start) / 1000);
e.reply(`gef0ckt lol: ${data.file} -> ${uuid}.${data.format[0].ext}, ~${lib.formatSize(size)}, speed: ${lib.calcSpeed(size, time)}`);
} }
else { else {
// recursive // recursive