Compare commits
9 Commits
v0.4.2-mai
...
2019269ded
| Author | SHA1 | Date | |
|---|---|---|---|
|
2019269ded
|
|||
|
b96451bee5
|
|||
|
bfb7df2d03
|
|||
|
ff3171d9e7
|
|||
|
4df6855ca4
|
|||
|
ab15fbcd1f
|
|||
|
3055371248
|
|||
|
580d73eeb8
|
|||
|
9e30c6db00
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -81,7 +81,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.4.2"
|
version = "0.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"imghdr",
|
"imghdr",
|
||||||
"lofty",
|
"lofty",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.4.2"
|
version = "0.4.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/// Gets the file type of a CoverArt given it's path
|
/// Gets the file type of a CoverArt given it's path
|
||||||
pub fn file_type_from_filepath(filepath: &str) -> Result<String, std::io::Error> {
|
pub fn file_type(filepath: &str) -> Result<String, std::io::Error> {
|
||||||
match imghdr::from_file(filepath) {
|
match imghdr::from_file(filepath) {
|
||||||
Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")),
|
Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")),
|
||||||
Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")),
|
Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")),
|
||||||
@@ -9,16 +9,6 @@ pub fn file_type_from_filepath(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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
@@ -27,27 +17,7 @@ mod tests {
|
|||||||
let filename = String::from("Sample Tracks 3.png");
|
let filename = String::from("Sample Tracks 3.png");
|
||||||
let filepath = format!("{directory}/{filename}");
|
let filepath = format!("{directory}/{filename}");
|
||||||
|
|
||||||
match super::file_type_from_filepath(&filepath) {
|
match super::file_type(&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) => {
|
Ok(filetype) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filetype, "png",
|
filetype, "png",
|
||||||
|
|||||||
15
src/lib.rs
15
src/lib.rs
@@ -5,7 +5,7 @@ pub mod types;
|
|||||||
|
|
||||||
pub mod test_util {
|
pub mod test_util {
|
||||||
pub mod util {
|
pub mod util {
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
@@ -39,19 +39,6 @@ pub mod test_util {
|
|||||||
std::fs::copy(src_path, dest_path)
|
std::fs::copy(src_path, dest_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_from_file(source_path: &str) -> Result<Vec<u8>, std::io::Error> {
|
|
||||||
match std::fs::File::open(source_path) {
|
|
||||||
Ok(mut file) => {
|
|
||||||
let mut data: Vec<u8> = Vec::new();
|
|
||||||
match file.read_to_end(&mut data) {
|
|
||||||
Ok(_) => Ok(data),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn file_exists(directory: &String, filename: &String) -> Result<bool, std::io::Error> {
|
pub fn file_exists(directory: &String, filename: &String) -> Result<bool, std::io::Error> {
|
||||||
match path_buf(directory, filename) {
|
match path_buf(directory, filename) {
|
||||||
Ok(pf) => Ok(pf.exists()),
|
Ok(pf) => Ok(pf.exists()),
|
||||||
|
|||||||
Reference in New Issue
Block a user