You've already forked immich
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:
16
web/src/lib/utils/byte-units.ts
Normal file
16
web/src/lib/utils/byte-units.ts
Normal 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]}`;
|
||||
}
|
Reference in New Issue
Block a user