2026-01-07 13:03:50 +07:00
|
|
|
export function convertBytes(bytes: number) {
|
2026-02-04 13:21:32 +07:00
|
|
|
if (!bytes) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 13:03:50 +07:00
|
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
|
|
|
|
|
|
if (bytes === 0) return '0 B';
|
|
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
|
let value = bytes;
|
|
|
|
|
|
|
|
|
|
while (value >= 1024 && i < units.length - 1) {
|
|
|
|
|
value /= 1024;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return `${value.toFixed(1)} ${units[i]}`;
|
|
|
|
|
}
|