IFF: Subtract header from file length

This commit is contained in:
Serial 2022-07-10 18:35:07 -04:00
parent 10b8462e7a
commit 464e78e222
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
3 changed files with 8 additions and 7 deletions

View file

@ -4,19 +4,20 @@ use crate::iff::chunk::Chunks;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
use byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt};
use byteorder::{ByteOrder, WriteBytesExt};
pub(in crate::id3::v2) fn write_to_chunk_file<B>(data: &mut File, tag: &[u8]) -> Result<()>
where
B: ByteOrder,
{
data.seek(SeekFrom::Current(4))?;
let file_size = data.read_u32::<B>()?;
data.seek(SeekFrom::Current(4))?;
// RIFF....WAVE
data.seek(SeekFrom::Current(12))?;
let file_len = data.metadata()?.len().saturating_sub(12);
let mut id3v2_chunk = (None, None);
let mut chunks = Chunks::<B>::new(u64::from(file_size)); // TODO
let mut chunks = Chunks::<B>::new(file_len);
while chunks.next(data).is_ok() {
if &chunks.fourcc == b"ID3 " || &chunks.fourcc == b"id3 " {

View file

@ -358,7 +358,7 @@ where
fn write_to_inner(data: &mut File, mut tag: AiffTextChunksRef<'_, T, AI>) -> Result<()> {
super::read::verify_aiff(data)?;
let file_len = data.metadata()?.len();
let file_len = data.metadata()?.len().saturating_sub(12);
let text_chunks = Self::create_text_chunks(&mut tag)?;

View file

@ -16,7 +16,7 @@ where
I: Iterator<Item = (&'a str, &'a str)>,
{
verify_wav(data)?;
let file_len = data.metadata()?.len();
let file_len = data.metadata()?.len().saturating_sub(12);
let mut riff_info_bytes = Vec::new();
create_riff_info(&mut tag.items, &mut riff_info_bytes)?;