tsk-44 (#47)
All checks were successful
Release Tagging / release (push) Successful in 28s
Rust Build / Check (push) Successful in 33s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Clippy (push) Successful in 40s
Rust Build / Test Suite (push) Successful in 52s
Rust Build / build (push) Successful in 35s
All checks were successful
Release Tagging / release (push) Successful in 28s
Rust Build / Check (push) Successful in 33s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Clippy (push) Successful in 40s
Rust Build / Test Suite (push) Successful in 52s
Rust Build / build (push) Successful in 35s
Reviewed-on: #47 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/// Gets the file type of a CoverArt given it's path
|
||||
pub fn file_type(filepath: &str) -> Result<String, std::io::Error> {
|
||||
pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error> {
|
||||
match imghdr::from_file(filepath) {
|
||||
Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")),
|
||||
Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")),
|
||||
@@ -9,6 +9,16 @@ pub fn file_type(filepath: &str) -> Result<String, std::io::Error> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the file type of a CoverArt given it's data
|
||||
pub fn file_type_from_data(data: &Vec<u8>) -> Result<String, std::io::Error> {
|
||||
match imghdr::from_bytes(data) {
|
||||
Some(imghdr::Type::Jpeg) => Ok(String::from("jpeg")),
|
||||
Some(imghdr::Type::Png) => Ok(String::from("png")),
|
||||
None => Err(std::io::Error::other("Image file not supported")),
|
||||
_ => Err(std::io::Error::other("Image file not supported")),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
@@ -17,7 +27,27 @@ mod tests {
|
||||
let filename = String::from("Sample Tracks 3.png");
|
||||
let filepath = format!("{directory}/{filename}");
|
||||
|
||||
match super::file_type(&filepath) {
|
||||
match super::file_type_from_filepath(&filepath) {
|
||||
Ok(filetype) => {
|
||||
assert_eq!(
|
||||
filetype, "png",
|
||||
"The file type of the CoverArt should have been png"
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_coverart_file_type_from_data() {
|
||||
let directory = String::from(crate::test_util::util::TESTFILEDIRECTORY);
|
||||
let filename = String::from("Sample Tracks 3.png");
|
||||
let filepath = format!("{directory}/{filename}");
|
||||
let data = crate::test_util::util::get_data_from_file(&filepath).unwrap();
|
||||
|
||||
match super::file_type_from_data(&data) {
|
||||
Ok(filetype) => {
|
||||
assert_eq!(
|
||||
filetype, "png",
|
||||
|
||||
Reference in New Issue
Block a user