diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 11:34:45 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 11:34:45 +0530 |
commit | 6db07e2e69f7f674191311719054a245e8c8b886 (patch) | |
tree | ac9bac2d4a0f031c2b267fc5d49eef5f0a3aee7c /src/lib.rs | |
parent | a19e3d76fe559f59be467b4967156509e6f26715 (diff) |
Add byte formatting
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -6,6 +6,12 @@ pub struct WalkOptions { } impl WalkOptions { + pub fn format_bytes(&self, b: u64) -> String { + use byte_unit::Byte; + Byte::from_bytes(b as u128) + .get_appropriate_unit(false) + .format(2) + } pub fn iter_from_path(&self, path: &Path) -> WalkDir { WalkDir::new(path) .preload_metadata(true) @@ -57,7 +63,12 @@ mod aggregate { } } - writeln!(out, "{}\t{}", num_bytes, path.as_ref().display())?; + writeln!( + out, + "{}\t{}", + options.format_bytes(num_bytes), + path.as_ref().display() + )?; } Ok(res) } |