mirror of
https://github.com/immich-app/immich.git
synced 2026-01-26 13:47:32 -05:00
* platform clients * uppercase http method * fix hot reload * custom user agent * init before app launch * set defaults * move to bootstrap * unrelated change * disable disk cache by default * optimized decoding * remove incremental * android impl * memory optimization * lock approach is slower on ios * conditional cronet * clarify parameter * enable disk cache * set user agent * flutter-side decode * optimized http * fixed locking * refactor * potential race conditions * embedded cronet * refactor, fix capacity handling * fast path for known content length * ios optimizations * re-enable cache * formatting * bump concurrency * clear cache button * fix eviction race condition * add extra cancellation check * tighten dispose * better error handling * fix disposal --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
26 lines
688 B
Dart
26 lines
688 B
Dart
import 'dart:math';
|
|
|
|
String formatBytes(int bytes) {
|
|
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]}";
|
|
}
|
|
|
|
String formatHumanReadableBytes(int bytes, int decimals) {
|
|
if (bytes <= 0) return "0 B";
|
|
const suffixes = ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
var i = (log(bytes) / log(1024)).floor();
|
|
return '${(bytes / pow(1024, i)).toStringAsFixed(decimals)} ${suffixes[i]}';
|
|
}
|