fileSize method

Future<String> fileSize({
  1. int decimal = 1,
})

Implementation

Future<String> fileSize({int decimal = 1}) async {
  int bytes = await length();
  if (bytes <= 0) {
    return "0 B";
  }
  const suffixes = ["B", "KB", "MB", "TB", "PB", "EB", "ZB", "YB"];
  final index = (log(bytes) / log(1024)).floor();
  return "${(bytes / pow(1024, index)).toStringAsFixed(decimal)} ' ' ${suffixes[index]}";
}