getFileSize
获取文件大小
examples
getFileSize(100) //100.00B
getFileSize(200) //200.00B
getFileSize(1000) //1000.00B
getFileSize(2000) //1.95KB
source code
const getFileSize = (size) => {
let fileSize = size;
let count = 0;
let units = ['B', 'KB', 'MB', 'GB', 'TB'];
while (fileSize > 1024) {
fileSize = fileSize / 1024;
count++;
}
return units[count] ? `${fileSize.toFixed(2)}${units[count]}` : size;
};