Skip to content

Instantly share code, notes, and snippets.

@adamlofts
Created December 9, 2016 12:40
Show Gist options
  • Save adamlofts/b354b1f3007c8aec65ad4b33eb346fc1 to your computer and use it in GitHub Desktop.
Save adamlofts/b354b1f3007c8aec65ad4b33eb346fc1 to your computer and use it in GitHub Desktop.
String formatFileSize(int b) {
const List<String> suffix = const [
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
];
num v = b.toDouble();
int c = 0;
while (v > 1024) {
v = v / 1024;
c += 1;
}
return "${prettyFormat(v)} ${suffix[c]}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment