From 99296a8272bd83e90e78bb5d0ae0d8c205146714 Mon Sep 17 00:00:00 2001 From: Vincent Swarte Date: Sun, 14 Apr 2024 21:11:58 +0000 Subject: [PATCH] Make zlibdecoder generic over std::io::Read --- crates/cli/src/describe.rs | 2 +- crates/formats/src/entryfilelist.rs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/cli/src/describe.rs b/crates/cli/src/describe.rs index 91ed318..02eebd6 100644 --- a/crates/cli/src/describe.rs +++ b/crates/cli/src/describe.rs @@ -29,7 +29,7 @@ pub fn describe_entryfilelist(dvd_bnd: &DvdBnd, name: &str) -> Result<(), Box EntryFileList<'a> { }) } - pub fn content(&self) -> Result, EntryFileListError> { + pub fn content_iter(&self) -> Result, EntryFileListError> { let mut decoder = ZlibDecoder::new(self.compressed); let _unk0 = decoder.read_u32::()?; @@ -103,19 +103,19 @@ impl<'a> std::fmt::Debug for EntryFileList<'a> { } #[derive(Debug)] -pub struct SectionIter<'a, TElement> { - decoder: ZlibDecoder<&'a [u8]>, +pub struct SectionIter { + decoder: ZlibDecoder, header: EntryFileListHeader, entry_count: usize, entries_read: usize, - _marker: PhantomData, + _marker: PhantomData, } -impl<'a, TElement> SectionIter<'a, TElement> { +impl SectionIter { fn skip_to_end(&mut self) -> io::Result<()> { if self.entries_read != self.entry_count { let remaining = - (self.entry_count - self.entries_read) * std::mem::size_of::(); + (self.entry_count - self.entries_read) * std::mem::size_of::(); std::io::copy( &mut self.decoder.by_ref().take(remaining as u64), &mut std::io::sink(), @@ -146,17 +146,17 @@ pub trait SectionElement: Sized { Self: Sized; } -impl<'a, TElement> Iterator for SectionIter<'a, TElement> +impl Iterator for SectionIter where - TElement: SectionElement, + T: SectionElement, { - type Item = io::Result; + type Item = io::Result; fn next(&mut self) -> Option { if self.entries_read < self.entry_count { let result = (self.entries_read..self.entry_count) .next() - .map(|_| TElement::read(&mut self.decoder)); + .map(|_| T::read(&mut self.decoder)); self.entries_read += 1; @@ -186,8 +186,8 @@ impl SectionElement for Unk1 { } } -impl<'a> SectionIter<'a, Unk1> { - pub fn next_section(mut self) -> Result, EntryFileListError> { +impl SectionIter { + pub fn next_section(mut self) -> Result, EntryFileListError> { self.skip_to_end()?; self.skip_to_alignment()?; @@ -238,8 +238,8 @@ impl SectionElement for UnkString { } } -impl<'a> SectionIter<'a, Unk2> { - pub fn next_section(mut self) -> Result, EntryFileListError> { +impl SectionIter { + pub fn next_section(mut self) -> Result, EntryFileListError> { self.skip_to_end()?; self.skip_to_alignment()?;