1from __future__ import annotations
2
3
4def format_bytes(size: int, precision: int = 1) -> str:
5 """Format a byte count as a human-readable string."""
6 if size >= 1_000_000_000:
7 return f"{size / 1_000_000_000:.{precision}f} GB"
8 if size >= 1_000_000:
9 return f"{size / 1_000_000:.{precision}f} MB"
10 if size >= 1_000:
11 return f"{size / 1_000:.{precision}f} KB"
12 return f"{size} B"