diff options
author | rabite <rabite@posteo.de> | 2019-01-21 17:47:58 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-01-21 17:47:58 +0100 |
commit | 8ad1b657ec3d20bab2199b33a22ff9a191dfe58d (patch) | |
tree | 9cf9d11a7f40060c0a5ceb8b72c9577f443b5614 /src/files.rs | |
parent | 724cc61680e14d45fb7c0e5ebac525b71e7a1381 (diff) |
got file sizes working in listview
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/files.rs b/src/files.rs index a35a4b1..2d83bd9 100644 --- a/src/files.rs +++ b/src/files.rs @@ -45,6 +45,23 @@ impl File { // mtime: None } } + pub fn calculate_size(&self) -> (usize, String) { + let mut unit = 0; + let mut size = self.size.unwrap(); + while size > 1024 { + size /= 1024; + unit += 1; + } + let unit = match unit { + 0 => "", + 1 => " KB", + 2 => " GB", + 3 => " TB", + 4 => "wtf are you doing", + _ => "" + }.to_string(); + (size, unit) + } } pub fn get_files(dir: &str) -> Result<Files, std::io::Error> { |