From 33484bfa971b8626ad96cc12a4033b96b759656e Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Date: Sun, 13 Nov 2022 05:08:00 +0000 Subject: [PATCH] Add to_file() to VocFile --- src/voc.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/voc.rs b/src/voc.rs index 2679b06..11fe644 100644 --- a/src/voc.rs +++ b/src/voc.rs @@ -1,6 +1,6 @@ use std::fmt; use std::fs::File; -use std::io::{Read, Seek, SeekFrom}; +use std::io::{Read, Seek, SeekFrom, Write}; #[derive(Clone, Copy, Debug)] pub enum Codec { @@ -33,8 +33,7 @@ pub struct VocFile { } impl VocFile { - pub(crate) fn from_file(file_name: &str) -> Self { - println!("Parsing {} ...", file_name); + pub fn from_file(file_name: &str) -> Self { let mut fp = File::open(file_name).unwrap(); // Signature - Creative Voice File @@ -184,6 +183,12 @@ impl VocFile { result } + + pub fn to_file(&self, filename: &str) { + let mut fp = File::create(filename).unwrap(); + drop(fp.write(&self.to_bytes())); + drop(fp.flush()); + } } type BlockT = Box;