mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-10-01 22:49:10 +00:00
10b8f6f414
Also, reverse the way columns are rendered: before, a column took a stat and a name to render; now, a file takes a column type to render. This means that most of the File data/methods can be private.
17 lines
469 B
Rust
17 lines
469 B
Rust
fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> ~str {
|
|
let mut prefix = 0;
|
|
while amount > kilo {
|
|
amount /= kilo;
|
|
prefix += 1;
|
|
}
|
|
return format!("{:4}{}", amount, prefixes[prefix]);
|
|
}
|
|
|
|
pub fn formatBinaryBytes(amount: u64) -> ~str {
|
|
formatBytes(amount, 1024, ~[ "B ", "KiB", "MiB", "GiB", "TiB" ])
|
|
}
|
|
|
|
pub fn formatDecimalBytes(amount: u64) -> ~str {
|
|
formatBytes(amount, 1000, ~[ "B ", "KB", "MB", "GB", "TB" ])
|
|
}
|