Skip to content

Instantly share code, notes, and snippets.

@okjake
Created February 23, 2013 22:08
Show Gist options
  • Select an option

  • Save okjake/5021573 to your computer and use it in GitHub Desktop.

Select an option

Save okjake/5021573 to your computer and use it in GitHub Desktop.
human readable filesizes
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