feat: change size formatting to k8s style (e.g. 3Gi, 4Ti)
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -30,8 +30,28 @@ pub fn get_meta_from_env() -> HashMap<String, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_size_human_readable(size: u64) -> String {
|
pub fn format_size_human_readable(size: u64) -> String {
|
||||||
let options = FormatSizeOptions::from(BINARY).decimal_places(1);
|
const UNITS: &[&str] = &["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
|
||||||
humansize::format_size(size, options)
|
const THRESHOLD: u64 = 1024;
|
||||||
|
|
||||||
|
if size == 0 {
|
||||||
|
return "0".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut size_f = size as f64;
|
||||||
|
let mut unit_index = 0;
|
||||||
|
|
||||||
|
while size_f >= THRESHOLD as f64 && unit_index < UNITS.len() - 1 {
|
||||||
|
size_f /= THRESHOLD as f64;
|
||||||
|
unit_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if unit_index == 0 {
|
||||||
|
format!("{}", size)
|
||||||
|
} else if size_f.fract() == 0.0 {
|
||||||
|
format!("{}{}", size_f as u64, UNITS[unit_index])
|
||||||
|
} else {
|
||||||
|
format!("{:.1}{}", size_f, UNITS[unit_index])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_size(size: u64, human_readable: bool) -> String {
|
pub fn format_size(size: u64, human_readable: bool) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user