nexus/lib/helpers/extensions/size_to_string.dart
Henry-Hiles d2ec5f035b
treewide: use dot shorthands where possible
Now this feature is stable, we should use it. I might have missed some usecases, but these can be added in future commits.
2026-06-02 12:50:56 -04:00

15 lines
403 B
Dart

import "package:fast_immutable_collections/fast_immutable_collections.dart";
extension SizeToString on int {
String get sizeAsString {
const suffixes = IListConst(["B", "KB", "MB", "GB", "TB", "PB"]);
var i = 0;
var size = toDouble();
while (size > 1024 && i < suffixes.length - 1) {
size /= 1024;
i++;
}
return "${size.toStringAsFixed(2)} ${suffixes[i]}";
}
}