Skip to content

Commit

Permalink
Fix:Byte conversion to use 1000 instead of 1024 to be accurate with a…
Browse files Browse the repository at this point in the history
…bbrevs #3386
  • Loading branch information
advplyr committed Sep 7, 2024
1 parent 423a212 commit 4ddd278
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
2 changes: 1 addition & 1 deletion client/plugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 0 additions & 13 deletions server/utils/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ddd278

Please sign in to comment.