MCPcopy Create free account
hub / github.com/AI45Lab/Code / format_size

Function format_size

core/src/tools/builtin/ls.rs:94–104  ·  view source on GitHub ↗
(bytes: u64)

Source from the content-addressed store, hash-verified

92}
93
94fn format_size(bytes: u64) -> String {
95 if bytes < 1024 {
96 format!("{}B", bytes)
97 } else if bytes < 1024 * 1024 {
98 format!("{:.1}KB", bytes as f64 / 1024.0)
99 } else if bytes < 1024 * 1024 * 1024 {
100 format!("{:.1}MB", bytes as f64 / (1024.0 * 1024.0))
101 } else {
102 format!("{:.1}GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
103 }
104}
105
106#[cfg(test)]
107mod tests {

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected