/** * Render a byte count as a short, human-readable size (e.g. `512 B`, `2 KB`, * `3.5 MB`, `2.0 GB`). Non-finite or non-positive inputs yield an empty string * so callers can treat "no usable size" uniformly. */ export function formatBytes(bytes: number): string { if (!Number.isFinite(bytes) || bytes <= 0) return ''; if (bytes < 1024) return `${bytes} B`; const kb = bytes / 1024; if (kb < 1024) return `${Math.round(kb)} KB`; const mb = kb / 1024; if (mb < 1024) return mb < 10 ? `${mb.toFixed(1)} MB` : `${Math.round(mb)} MB`; const gb = mb / 1024; return gb < 10 ? `${gb.toFixed(1)} GB` : `${Math.round(gb)} GB`; }