4 function bytesToSize(bytes) {
5 var sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
6 if (bytes == 0) return 'n/a';
7 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
8 if (i == 0) { return (bytes / Math.pow(1024, i)) + ' ' + sizes[i]; }
9 return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];