Skip to content

Instantly share code, notes, and snippets.

@xargr
Created March 7, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xargr/33e55c66e5ba33f0b512558b0ab2f3e6 to your computer and use it in GitHub Desktop.
Save xargr/33e55c66e5ba33f0b512558b0ab2f3e6 to your computer and use it in GitHub Desktop.
const bytesToSize = bytes => {
var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
if (bytes == 0) return "0 Byte";
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment