const GB: i64 = 1_000_000_000;
const MB: i64 = 1_000_000;
const KB: i64 = 1_000;
pub const BYTES_PER_MIB: i64 = 1 << 20;
pub const BYTES_PER_GIB: i64 = 1 << 30;
pub fn one_decimal(value: f64) -> String {
let formatted = format!("{value:.1}");
formatted
.strip_suffix(".0")
.unwrap_or(&formatted)
.to_owned()
}
pub fn format_bytes(bytes: i64) -> String {
if bytes >= GB {
format!("{} GB", one_decimal(bytes as f64 / GB as f64))
} else if bytes >= MB {
format!("{} MB", bytes / MB)
} else if bytes >= KB {
format!("{} KB", bytes / KB)
} else {
format!("{bytes} B")
}
}