ente/lib/utils/data_util.dart

16 lines
451 B
Dart
Raw Normal View History

2021-02-01 11:02:30 +00:00
double convertBytesToGBs(final int bytes, {int precision = 2}) {
return double.parse(
(bytes / (1024 * 1024 * 1024)).toStringAsFixed(precision));
}
2021-03-02 06:35:10 +00:00
final kStorageUnits = ["bytes", "KB", "MB", "GB", "TB"];
String convertBytesToReadableFormat(int bytes) {
int storageUnitIndex = 0;
while (bytes >= 1024) {
storageUnitIndex++;
bytes = (bytes / 1024).round();
}
return bytes.toString() + " " + kStorageUnits[storageUnitIndex];
}