1
0
mirror of https://github.com/immich-app/immich.git synced 2025-06-29 05:21:38 +02:00

feat(server,web,mobile): Use binary prefixes for data sizes (#1009)

This commit is contained in:
Kiel Hurley
2022-11-25 06:39:27 +13:00
committed by GitHub
parent df0a059a02
commit 976d347623
8 changed files with 64 additions and 101 deletions

View File

@ -0,0 +1,16 @@
export function getHumanReadableBytes(bytes: number): string {
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
let magnitude = 0;
let remainder = bytes;
while (remainder >= 1024) {
if (magnitude + 1 < units.length) {
magnitude++;
remainder /= 1024;
} else {
break;
}
}
return `${remainder.toFixed(magnitude == 0 ? 0 : 1)} ${units[magnitude]}`;
}