Skip to content

Commit

Permalink
Add support for more SI suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Jul 23, 2024
1 parent f1011e4 commit 8dc6f2b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use thiserror::Error;
enum SizeBytes {
Byte,
KiB,
KB,
MiB,
MB,
GiB,
GB,
}

impl TryFrom<&str> for SizeBytes {
Expand All @@ -16,8 +19,11 @@ impl TryFrom<&str> for SizeBytes {
match v {
"B" => Ok(Self::Byte),
"KiB" => Ok(Self::KiB),
"kB" => Ok(Self::KB),
"MiB" => Ok(Self::MiB),
"MB" => Ok(Self::MB),
"GiB" => Ok(Self::GiB),
"GB" => Ok(Self::GB),
_ => Err("Unknown unit"),
}
}
Expand All @@ -27,9 +33,12 @@ impl SizeBytes {
fn to_bytes(self) -> usize {
match self {
Self::Byte => 1,
Self::KiB => 1_000,
Self::MiB => 1_000_000,
Self::GiB => 1_000_000_000,
Self::KiB => 1024,
Self::MiB => 1024*1024,
Self::GiB => 1024*1024*1024,
Self::KB => 1000,
Self::MB => 1000*1000,
Self::GB => 1000*1000*1000,
}
}
}
Expand Down

0 comments on commit 8dc6f2b

Please sign in to comment.