Created
October 6, 2021 18:41
-
-
Save stefanocudini/46a1f068d66cef46aa6a7d3511d68bf5 to your computer and use it in GitHub Desktop.
filesize human in nodejs/javascript
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
function filesize(bytes) { | |
if (bytes === 0) return bytes; | |
var sizes = ['Bytes','KB','MB','GB','TB'], | |
i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
return Math.round(bytes / Math.pow(1024, i), 1) + ' ' + sizes[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment