用于字節(jié)大小的轉(zhuǎn)換
bytesToSize(bytes) {
if (bytes === 0) {
return '0 B';
}
let k = 1024;
let sizes = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = Math.floor(Math.log(bytes) / Math.log(k));
let num = (bytes / Math.pow(k, i)).toFixed(1) > Math.floor((bytes / Math.pow(k, i))) ?
(bytes / Math.pow(k, i)).toFixed(1) : Math.floor((bytes / Math.pow(k, i)));
return num + ' ' + sizes[i];
}