Skip to content

Instantly share code, notes, and snippets.

@execmd
Created August 5, 2015 13:47
Show Gist options
  • Select an option

  • Save execmd/f54ed94031fce8b74328 to your computer and use it in GitHub Desktop.

Select an option

Save execmd/f54ed94031fce8b74328 to your computer and use it in GitHub Desktop.
Parsing size in bytes to readable format
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