Use unwrap() for writing to cursor

Writing to cursors should never fail
master
Simon Bruder 2020-06-25 18:47:11 +02:00
parent 8c8f954bbe
commit 2b0b66ddca
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
2 changed files with 8 additions and 9 deletions

View File

@ -1,6 +1,5 @@
use std::io::{Cursor, Write};
use anyhow::Result;
use byteorder::{LittleEndian, WriteBytesExt};
use log::{debug, trace};
@ -88,7 +87,7 @@ impl WaveChunk for RIFFHeader {
}
}
pub fn build_wav(format: WaveFormat, data: &[u8]) -> Result<Vec<u8>> {
pub fn build_wav(format: WaveFormat, data: &[u8]) -> Vec<u8> {
debug!("Building file");
let riff_header = RIFFHeader {
file_size: 82 + data.len() as u32,
@ -104,15 +103,15 @@ pub fn build_wav(format: WaveFormat, data: &[u8]) -> Result<Vec<u8>> {
let mut buf = Cursor::new(Vec::new());
trace!("Building RIFF header");
buf.write_all(&riff_header.to_chunk())?;
buf.write_all(&riff_header.to_chunk()).unwrap();
trace!("Building fmt chunk");
buf.write_all(&format.to_chunk())?;
buf.write_all(&format.to_chunk()).unwrap();
trace!("Building fact chunk");
buf.write_all(&fact.to_chunk())?;
buf.write_all(&fact.to_chunk()).unwrap();
write!(buf, "data")?;
write!(buf, "data").unwrap();
buf.write_u32::<LittleEndian>(data.len() as u32).unwrap();
buf.write_all(data)?;
buf.write_all(data).unwrap();
Ok(buf.into_inner())
buf.into_inner()
}

View File

@ -244,7 +244,7 @@ pub struct Sound<'a> {
impl Sound<'_> {
pub fn to_wav(&self) -> Result<Vec<u8>> {
match &self.format.tag {
FormatTag::ADPCM => adpcm::build_wav(self.format.clone().try_into()?, self.data),
FormatTag::ADPCM => Ok(adpcm::build_wav(self.format.clone().try_into()?, self.data)),
_ => Err(Error::UnsupportedFormat(self.format.tag.clone()).into()),
}
}