gist:11075625

Lei Q
2014-04-19T06:08:57Z

gistfile1.js

| app.filter('bytes', function() {
| return function(bytes, precision) {
| if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
| if (typeof precision === 'undefined') precision = 1;
| if (bytes === 0) return '0kb'
| var units = ['bytes', 'kb', 'mb', 'gb', 'tb', 'pb'],
| number = Math.floor(Math.log(bytes) / Math.log(1024));
| return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
| }
| });