// A size in bytes, in the largest unit that keeps it above one: "1.4 TB", // "820 GB", "12 KB". Decimal units, as drives are sold and as `df -H` shows. const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; export function formatBytes(n: number): string { let v = n; let u = 0; while (v >= 1000 && u < UNITS.length - 1) { v /= 1000; u++; } const digits = u === 0 || v >= 100 ? 0 : 1; return `${v.toFixed(digits)} ${UNITS[u]}`; }