import mimeType from 'mime-types';
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
export const bytesToSize = (bytes) => {
if (!bytes) {
return '0 B';
}
const sized = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return (bytes / Math.pow(1024, sized)).toFixed(2) + sizes[sized];
}
export const getFileSuffix = (type) => {
return mimeType.extension(type);
};
创建 mine-type标头,和计算文件大小工具类
最新推荐文章于 2024-05-11 13:55:50 发布