shared.ts
Raw
1export function humanFileSize(size: number) {
2 if (size < 1024) return `${size} B`;
3 const i = Math.min(4, Math.floor(Math.log(size) / Math.log(1024)));
4 return `${(size / 1024 ** i).toFixed(2)} ${["B", "KiB", "MiB", "GiB", "TiB"][i]}`;
5}
6