Format bytes into human-readable size (B, K, M, G)
(bytes: u64)
| 4 | |
| 5 | /// Format bytes into human-readable size (B, K, M, G) |
| 6 | pub fn format_size(bytes: u64) -> String { |
| 7 | const KB: u64 = 1024; |
| 8 | const MB: u64 = KB * 1024; |
| 9 | const GB: u64 = MB * 1024; |
| 10 | |
| 11 | if bytes >= GB { |
| 12 | format!("{:.1}G", bytes as f64 / GB as f64) |
| 13 | } else if bytes >= MB { |
| 14 | format!("{:.1}M", bytes as f64 / MB as f64) |
| 15 | } else if bytes >= KB { |
| 16 | format!("{:.1}K", bytes as f64 / KB as f64) |
| 17 | } else { |
| 18 | format!("{}B", bytes) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | /// Check if a file is executable |
| 23 | pub fn is_executable(path: &Path) -> bool { |
no outgoing calls
no test coverage detected