formatBytes static method
Implementation
static String formatBytes(double bytes, [String delim = ""]) {
if (bytes < 1) {
return "0 B";
}
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
final digitGroups = (math.log(bytes) / math.log(1024)).floor();
if (digitGroups < 1) {
return "${bytes.toStringAsFixed(1)}B";
}
final index =
digitGroups > units.length - 1 ? units.length - 1 : digitGroups;
return "${(bytes / (math.pow(1024, index))).toStringAsFixed(1)}$delim${units[index]}";
}