From 4ddd2788f0bedfa4b820af46dd64e67e11ea68c8 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 7 Sep 2024 16:52:42 -0500 Subject: [PATCH] Fix:Byte conversion to use 1000 instead of 1024 to be accurate with abbrevs #3386 --- client/plugins/utils.js | 2 +- server/utils/fileUtils.js | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/client/plugins/utils.js b/client/plugins/utils.js index ffcd33ad..160ff943 100644 --- a/client/plugins/utils.js +++ b/client/plugins/utils.js @@ -11,7 +11,7 @@ Vue.prototype.$bytesPretty = (bytes, decimals = 2) => { if (isNaN(bytes) || bytes == 0) { return '0 Bytes' } - const k = 1024 + const k = 1000 const dm = decimals < 0 ? 0 : decimals const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] const i = Math.floor(Math.log(bytes) / Math.log(k)) diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index e4bb53a0..b0c73d6c 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -131,19 +131,6 @@ async function readTextFile(path) { } module.exports.readTextFile = readTextFile -function bytesPretty(bytes, decimals = 0) { - if (bytes === 0) { - return '0 Bytes' - } - const k = 1000 - var dm = decimals < 0 ? 0 : decimals - const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - const i = Math.floor(Math.log(bytes) / Math.log(k)) - if (i > 2 && dm === 0) dm = 1 - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i] -} -module.exports.bytesPretty = bytesPretty - /** * Get array of files inside dir * @param {string} path