Created
December 9, 2016 12:40
-
-
Save adamlofts/b354b1f3007c8aec65ad4b33eb346fc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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