Compare commits

...

14 Commits

Author SHA1 Message Date
1bb31d7da7 tsk-44: Merge conflict
Some checks failed
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 36s
Rust Build / Rustfmt (pull_request) Failing after 35s
Rust Build / Clippy (pull_request) Successful in 43s
Rust Build / build (pull_request) Successful in 39s
2025-10-21 12:13:50 -04:00
87a0f799cc tsk-44: Version bump
All checks were successful
Rust Build / Check (pull_request) Successful in 36s
Rust Build / Test Suite (pull_request) Successful in 34s
Rust Build / Rustfmt (pull_request) Successful in 36s
Rust Build / Clippy (pull_request) Successful in 41s
Rust Build / build (pull_request) Successful in 37s
2025-10-21 12:10:22 -04:00
9243c75aac tsk-44: Code formatting 2025-10-21 12:10:08 -04:00
54001860ca tsk-44: Function name change 2025-10-21 12:09:58 -04:00
f20b16e59f tsk-44: Added function to get CoverArt type from data 2025-10-21 12:08:55 -04:00
2019269ded tsk-44: Version bump
All checks were successful
Rust Build / Test Suite (pull_request) Successful in 38s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 46s
Rust Build / Check (pull_request) Successful in 35s
2025-10-20 20:57:54 -04:00
b96451bee5 tsk-44: Code formatting
All checks were successful
Rust Build / Check (pull_request) Successful in 43s
Rust Build / Test Suite (pull_request) Successful in 33s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 38s
Rust Build / build (pull_request) Successful in 1m0s
2025-10-20 20:55:07 -04:00
bfb7df2d03 tsk-44: Test changes 2025-10-20 20:54:51 -04:00
ff3171d9e7 tsk-44: Updating tests 2025-10-20 20:54:36 -04:00
4df6855ca4 tsk-44: Added rand crate 2025-10-20 20:54:21 -04:00
ab15fbcd1f tsk-44: Adding test 2025-10-20 20:33:45 -04:00
3055371248 tsk-44: cargo update 2025-10-20 20:24:08 -04:00
580d73eeb8 tsk-44: Added detection module
Some checks failed
Rust Build / Clippy (pull_request) Successful in 1m5s
Rust Build / Test Suite (pull_request) Successful in 58s
Rust Build / Check (pull_request) Successful in 47s
Rust Build / build (pull_request) Successful in 1m5s
Rust Build / Rustfmt (pull_request) Failing after 1m19s
2025-10-20 20:19:37 -04:00
9e30c6db00 tsk-44: Added imghdr crate 2025-10-20 20:06:30 -04:00
4 changed files with 49 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -81,7 +81,7 @@ dependencies = [
[[package]]
name = "icarus_meta"
version = "0.4.1"
version = "0.4.2"
dependencies = [
"imghdr",
"lofty",

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_meta"
version = "0.4.1"
version = "0.4.2"
edition = "2024"
rust-version = "1.90"

View File

@@ -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",

View File

@@ -5,10 +5,11 @@ pub mod types;
pub mod test_util {
pub mod util {
use std::io::{self, Write};
use std::io::{self, Read, Write};
use rand::Rng;
// Function to save a Vec<u8> to a file
pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> {
let file = std::path::Path::new(file_path);
@@ -39,6 +40,19 @@ pub mod test_util {
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> {
match path_buf(directory, filename) {
Ok(pf) => Ok(pf.exists()),