-
-
Save bitfishxyz/fd49a6feb9f20986d4ae105f20e842a2 to your computer and use it in GitHub Desktop.
This file contains 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 bytesToSize (bytes) { | |
if (bytes === 0) return '0 B'; | |
var k = 1024; | |
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | |
var i = Math.floor(Math.log(bytes) / Math.log(k)) | |
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment