From dfe513b59637780443da5f2ff70cec14e2a3cadd Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Wed, 2 Dec 2020 22:27:14 -0800 Subject: [PATCH] iXML and axml cleanup impl --- src/wavereader.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/wavereader.rs b/src/wavereader.rs index 6a99416..1b54281 100644 --- a/src/wavereader.rs +++ b/src/wavereader.rs @@ -167,14 +167,9 @@ impl WaveReader { /// /// If there are no iXML metadata present in the file, /// Err(Error::ChunkMissing { "iXML" } will be returned. - pub fn ixml(&mut self, buffer: &mut Vec) -> Result { - let ixml_sig: FourCC = FourCC::make(b"iXML"); - let mut chunk = self.chunk_reader(ixml_sig, 0)?; - - match chunk.read_to_end(buffer) { - Ok(read) => Ok(read), - Err(error) => Err(error.into()) - } + pub fn read_ixml(&mut self, buffer: &mut Vec) -> Result { + let ixml_fourcc = FourCC::make(b"iXML"); + self.read_chunk(ixml_fourcc, 0, buffer) } /// Read AXML data. @@ -182,19 +177,13 @@ impl WaveReader { /// By convention this will generally be ADM metadata. /// /// If there are no iXML metadata present in the file, - /// Err(Error::ChunkMissing { "axml" } will be returned. - pub fn axml(&mut self, buffer: &mut Vec) -> Result { - let axml_sig: FourCC = FourCC::make(b"axml"); - let mut chunk = self.chunk_reader(axml_sig, 0)?; - - match chunk.read_to_end(buffer) { - Ok(read) => Ok(read), - Err(error) => Err(error.into()) - } + /// Ok(0) will be returned + pub fn read_axml(&mut self, buffer: &mut Vec) -> Result { + let axml_fourcc = FourCC::make(b"axml"); + self.read_chunk(axml_fourcc, 0, buffer) } - /** * Validate file is readable. * @@ -339,6 +328,21 @@ impl WaveReader { /* Private Implementation */ Ok( RawChunkReader::new(&mut self.inner, start, length) ) } + fn read_chunk(&mut self, ident: FourCC, at: u32, buffer: &mut Vec) -> Result { + let result = self.chunk_reader(ident, at); + + match result { + Ok(mut chunk) => { + match chunk.read_to_end(buffer) { + Ok(read) => Ok(read), + Err(err) => Err(err.into()) + } + }, + Err(ParserError::ChunkMissing { signature : _} ) => Ok(0), + Err( any ) => Err(any.into()) + } + } + fn get_chunk_extent_at_index(&mut self, fourcc: FourCC, index: u32) -> Result<(u64,u64), ParserError> { let p = Parser::make(&mut self.inner)?.into_chunk_list()?;