Created
August 5, 2015 13:47
-
-
Save execmd/f54ed94031fce8b74328 to your computer and use it in GitHub Desktop.
Parsing size in bytes to readable format
This file contains hidden or 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
| function parseSize(size, power) { | |
| power = power || 1024; | |
| var pref = ['b', 'K', 'M', 'G', 'T'], sizes = [], i = 0; | |
| while (size > 1) { | |
| sizes.unshift((size % power) + pref[i]); | |
| size = Math.floor(size / power); | |
| i++; | |
| } | |
| return sizes.join(' '); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment