Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zhuifeng1017/81a0892a676856de1d0730f68daf8174 to your computer and use it in GitHub Desktop.
Save zhuifeng1017/81a0892a676856de1d0730f68daf8174 to your computer and use it in GitHub Desktop.
function humanFileSize(size) {
if(size==0){
return '0B';
}
var i = Math.floor( Math.log(size) / Math.log(1024) );
return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment