mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(server,web,mobile): Use binary prefixes for data sizes (#1009)
This commit is contained in:
parent
df0a059a02
commit
976d347623
8 changed files with 64 additions and 101 deletions
|
|
@ -1,15 +1,17 @@
|
|||
|
||||
String formatBytes(int bytes) {
|
||||
if (bytes < 1000) {
|
||||
return "$bytes B";
|
||||
} else if (bytes < 1000000) {
|
||||
final kb = (bytes / 1000).toStringAsFixed(1);
|
||||
return "$kb kB";
|
||||
} else if (bytes < 1000000000) {
|
||||
final mb = (bytes / 1000000).toStringAsFixed(1);
|
||||
return "$mb MB";
|
||||
} else {
|
||||
final gb = (bytes / 1000000000).toStringAsFixed(1);
|
||||
return "$gb GB";
|
||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
|
||||
|
||||
int magnitude = 0;
|
||||
double remainder = bytes.toDouble();
|
||||
while (remainder >= 1024) {
|
||||
if (magnitude + 1 < units.length) {
|
||||
magnitude++;
|
||||
remainder /= 1024;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "${remainder.toStringAsFixed(magnitude == 0 ? 0 : 1)} ${units[magnitude]}";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue