2014-05-24 00:14:40 +00:00
|
|
|
fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> StrBuf {
|
2014-05-04 20:33:14 +00:00
|
|
|
let mut prefix = 0;
|
|
|
|
while amount > kilo {
|
|
|
|
amount /= kilo;
|
|
|
|
prefix += 1;
|
|
|
|
}
|
|
|
|
return format!("{:4}{}", amount, prefixes[prefix]);
|
|
|
|
}
|
|
|
|
|
2014-05-24 00:14:40 +00:00
|
|
|
pub fn formatBinaryBytes(amount: u64) -> StrBuf {
|
2014-05-04 20:33:14 +00:00
|
|
|
formatBytes(amount, 1024, ~[ "B ", "KiB", "MiB", "GiB", "TiB" ])
|
|
|
|
}
|
|
|
|
|
2014-05-24 00:14:40 +00:00
|
|
|
pub fn formatDecimalBytes(amount: u64) -> StrBuf {
|
2014-05-04 20:33:14 +00:00
|
|
|
formatBytes(amount, 1000, ~[ "B ", "KB", "MB", "GB", "TB" ])
|
|
|
|
}
|