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 9ebc249
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 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,12 @@ impl TryFrom<&str> for SizeBytes {
match v {
"B" => Ok(Self::Byte),
"KiB" => Ok(Self::KiB),
"KB" => Ok(Self::KB),
"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 +34,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 Expand Up @@ -121,7 +131,7 @@ impl Time {
}

const FLOAT32_REGEX: &str = r"\d+(?:\.\d+)?";
const BYTES_REGEX: &str = r"[KMG]iB";
const BYTES_REGEX: &str = r"[kKMG]i?B";
const BITS_LONG_REGEX: &str = r"[kMG]?bits";
const BITS_SHORT_REGEX: &str = r"[kMG]?b";
const TIME_REGEX: &str = r"(?:\d+:)*\d+(?:\.\d+)?";
Expand Down

0 comments on commit 9ebc249

Please sign in to comment.