import {ceil, divide} from "lodash-es";

/**
 * 将文件大小转为字符串格式
 * @param fileSizeInBytes
 */
export const convertFileSizeToStr = (fileSizeInBytes: number): string => {
    if (fileSizeInBytes < 1024) {
        return fileSizeInBytes + "B";
    } else if (fileSizeInBytes < 1024 * 1024) {
        return (ceil(divide(fileSizeInBytes, 1024), 2)) + "KB";
    } else if (fileSizeInBytes < 1024 * 1024 * 1024) {
        return (ceil(divide(fileSizeInBytes, (1024 * 1024)), 2)) + "MB";
    } else {
        return (ceil(divide(fileSizeInBytes, (1024 * 1024 * 1024)), 2)) + "GB";
    }
}
