tsk-44 #47
@@ -1,21 +1,11 @@
|
||||
/// Gets the file type of a CoverArt given it's path
|
||||
pub fn file_type(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"))
|
||||
}
|
||||
Ok(None) => {
|
||||
Err(std::io::Error::other("Image file not supported"))
|
||||
}
|
||||
Err(err) => {
|
||||
Err(err)
|
||||
}
|
||||
_ => {
|
||||
Err(std::io::Error::other("Image file not supported"))
|
||||
}
|
||||
Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")),
|
||||
Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")),
|
||||
Ok(None) => Err(std::io::Error::other("Image file not supported")),
|
||||
Err(err) => Err(err),
|
||||
_ => Err(std::io::Error::other("Image file not supported")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +19,10 @@ mod tests {
|
||||
|
||||
match super::file_type(&filepath) {
|
||||
Ok(filetype) => {
|
||||
assert_eq!(filetype, "png", "The file type of the CoverArt should have been png");
|
||||
assert_eq!(
|
||||
filetype, "png",
|
||||
"The file type of the CoverArt should have been png"
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
|
||||
Reference in New Issue
Block a user