From f72fb8963f676c71bbdfb0a9fd4aeac9533fe0d2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 16:18:48 -0400 Subject: [PATCH] Added method to save coverart to the filesystem --- src/coverart.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/coverart.rs b/src/coverart.rs index d6741bf..55a2953 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -1,5 +1,8 @@ +use std::io::Write; + use serde::{Deserialize, Serialize}; + #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct CoverArt { pub id: uuid::Uuid, @@ -26,7 +29,25 @@ pub mod init { } impl CoverArt { - // TODO: Add method to save to filesystem + /// Saves the coverart to the filesystem + pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { + match std::fs::File::create(&self.path) { + Ok(mut file) => { + match file.write_all(&self.data) { + Ok(_) => { + Ok(()) + } + Err(err) => { + Err(err) + } + } + } + Err(err) => { + Err(err) + } + } + } + // TODO: Add method to remove from filesystem }