Would make sense to stop reading when the end is reached :)

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-04-17 17:09:32 -04:00
parent 7797c1e92b
commit 511aa597b2
2 changed files with 15 additions and 9 deletions

View file

@ -50,7 +50,9 @@ where
let chunk_len = list.len();
let mut metadata: HashMap<String, String> = HashMap::with_capacity(chunk_len as usize);
for _ in 0..chunk_len {
let mut reading = true;
while reading {
let fourcc = cursor.read_u32::<LittleEndian>()? as u32;
let size = cursor.read_u32::<LittleEndian>()? as u32;
@ -61,14 +63,18 @@ where
let val = std::str::from_utf8(&*buf)?;
metadata.insert(key, val.trim_matches(char::from(0)).to_string());
// Skip null byte
if size as usize % 2 != 0 {
cursor.set_position(cursor.position() + 1)
}
},
None => cursor.set_position(cursor.position() + u64::from(size)),
}
// Skip null byte
if size as usize % 2 != 0 {
cursor.set_position(cursor.position() + 1)
}
if cursor.position() >= cursor.get_ref().len() as u64 {
reading = false
}
}
Ok(Some(metadata))

View file

@ -1,6 +1,6 @@
use crate::{
impl_tag, traits::ReadPath, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite,
Picture, Result, TagType, ToAny, ToAnyTag,
impl_tag, traits::ReadPath, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Picture,
Result, TagType, ToAny, ToAnyTag, components::logic
};
use std::{collections::HashMap, fs::File, path::Path};
@ -15,7 +15,7 @@ impl ReadPath for WavInnerTag {
P: AsRef<std::path::Path>,
Self: Sized,
{
let data = crate::components::logic::read::wav(File::open(path)?)?;
let data = logic::read::wav(File::open(path)?)?;
Ok(Self { data })
}