From fa8643e73abc3c4678a7f12dd918c150bdd9ee1c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:08:20 -0400 Subject: [PATCH] Added function to save song to the filesystem --- src/song.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/song.rs b/src/song.rs index 2fbd3d9..107e547 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read,Write}; use crate::constants; use crate::init; @@ -150,4 +150,27 @@ impl Song { filename } + + pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { + match self.song_path() { + Ok(song_path) => { + match std::fs::File::create(&song_path) { + Ok(mut file) => { + match file.write_all(&self.data) { + Ok(_res) => { + Ok(()) + } + Err(err) => { + Err(err) + } + } + } + Err(err) => { + Err(err) + } + } + } + Err(err) => Err(err) + } + } }