Created
February 23, 2013 22:08
-
-
Save okjake/5021573 to your computer and use it in GitHub Desktop.
human readable filesizes
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
| var humanFilesize = function(bytes){ | |
| if (bytes < 1024) | |
| return bytes + ' bytes'; | |
| if (bytes < 1048576) | |
| return (bytes / 1024) + ' kB'; | |
| if (bytes < 1073741824) | |
| return bytes / 1048576 + ' MB'; | |
| if (bytes < 1099511627776) | |
| return (bytes / 1073741824) + ' GB'; | |
| return (bytes / 1099511627776) + ' TB'; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment