-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AdamQuadmon/adam
fix: improve size formatting and analysis output
- Loading branch information
Showing
3 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod file_operations; | ||
pub mod hashing; | ||
pub mod formatting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// Convert bytes to human readable string with appropriate unit | ||
pub fn format_size(bytes: u64) -> String { | ||
const KB: u64 = 1024; | ||
const MB: u64 = KB * 1024; | ||
const GB: u64 = MB * 1024; | ||
|
||
if bytes >= GB { | ||
format!("{:.2} GB", bytes as f64 / GB as f64) | ||
} else if bytes >= MB { | ||
format!("{:.2} MB", bytes as f64 / MB as f64) | ||
} else if bytes >= KB { | ||
format!("{:.2} KB", bytes as f64 / KB as f64) | ||
} else { | ||
format!("{} B", bytes) | ||
} | ||
} |