diff options
| author | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
|---|---|---|
| committer | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
| commit | 449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch) | |
| tree | c131c3528c4d517f56e19b854a7453fedb097d40 /lib/utils/file_utils.dart | |
| download | aves-src-master.tar.gz aves-src-master.zip | |
Diffstat (limited to 'lib/utils/file_utils.dart')
| -rw-r--r-- | lib/utils/file_utils.dart | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/utils/file_utils.dart b/lib/utils/file_utils.dart new file mode 100644 index 0000000..4f3f0b7 --- /dev/null +++ b/lib/utils/file_utils.dart @@ -0,0 +1,16 @@ +import 'package:intl/intl.dart'; + +const kilo = 1024; +const mega = kilo * kilo; +const giga = mega * kilo; +const tera = giga * kilo; + +String formatFileSize(String locale, int size, {int round = 2}) { + if (size < kilo) return '$size B'; + + final compactFormatter = NumberFormat('0${round > 0 ? '.${'0' * round}' : ''}', locale); + if (size < mega) return '${compactFormatter.format(size / kilo)} KB'; + if (size < giga) return '${compactFormatter.format(size / mega)} MB'; + if (size < tera) return '${compactFormatter.format(size / giga)} GB'; + return '${compactFormatter.format(size / tera)} TB'; +} |
