Skip to content

Commit

Permalink
Merge pull request #906 from opencb/TASK-5931
Browse files Browse the repository at this point in the history
TASK-5931 - File browser showing file sizes in decimal bytes
  • Loading branch information
jmjuanes authored May 14, 2024
2 parents 023f596 + d63eee3 commit cc72155
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/utils-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,16 @@ export default class UtilsNew {
delete obj[last];
}

static getDiskUsage(bytes, numDecimals = 2) {
static getDiskUsage(bytes, numDecimals = 2, useInternationalSystem = false) {
if (bytes === 0) {
return "0 Byte";
}
const k = 1000;
const k = useInternationalSystem ? 1000 : 1024;
const dm = numDecimals ? numDecimals : 2;
const sizes = [" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"];
const sizesBinary = [" Bytes", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB", " YiB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i];
return (bytes / Math.pow(k, i)).toFixed(dm) + (useInternationalSystem ? sizes[i] : sizesBinary[i]);
}

static getDatetime(timestamp) {
Expand Down

0 comments on commit cc72155

Please sign in to comment.