/**
 * @description: 格式化文件大小
 * @author ChenRui
 * @date 2021/4/6 19:45
 */
function encode(value: string) {
  if (null == value || value == "") {
    return "0 Bytes";
  }
  const unitArr = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  let index = 0;
  const srcsize = parseFloat(value);
  index = Math.floor(Math.log(srcsize) / Math.log(1024));
  let size: any = srcsize / Math.pow(1024, index);
  size = size.toFixed(2); //保留的小数位数
  return size + unitArr[index];
}
const formatFileSize = (value: string) => {
  return encode(value);
};

export default formatFileSize;
