formatBytes static method

String formatBytes(
  1. int bytes, [
  2. int precision = 2
])

Format bytes to human readable string.

Implementation

static String formatBytes(int bytes, [int precision = 2]) {
  final base = (bytes == 0) ? 0 : (math.log(bytes) / math.log(1024)).floor();
  final size = bytes / powBase[base];
  final formattedSize = size.toStringAsFixed(precision);
  return '$formattedSize ${suffix[base]}';
}