From 6d3d28f3531671c7e21a66e0d83ce4fce06148bc Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Sun, 13 Aug 2023 17:31:45 +0900 Subject: [PATCH] :zap: Introduce EntryDataReader --- lib/src/archive/entry.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/archive/entry.rs b/lib/src/archive/entry.rs index 4056bcc1..988f23c2 100644 --- a/lib/src/archive/entry.rs +++ b/lib/src/archive/entry.rs @@ -38,10 +38,9 @@ pub trait Entry: SealedIntoChunks { /// Readable archive entry. pub trait ReadEntry: Entry { - type Reader: Read; fn header(&self) -> &EntryHeader; fn metadata(&self) -> &Metadata; - fn into_reader(self, option: ReadOption) -> io::Result; + fn into_reader(self, option: ReadOption) -> io::Result; } /// Solid mode entries block. @@ -71,8 +70,16 @@ impl Entry for ChunkEntry { } } -/// [`Read`] -pub struct EntryReader(DecompressReader<'static, DecryptReader>); +/// Reader for Entry data. this struct impl [`Read`] trait. +pub struct EntryDataReader(EntryReader>>); + +impl Read for EntryDataReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0.read(buf) + } +} + +pub(crate) struct EntryReader(DecompressReader<'static, DecryptReader>); impl Read for EntryReader { fn read(&mut self, buf: &mut [u8]) -> io::Result { @@ -345,8 +352,6 @@ impl Entry for NonSolidReadEntry { } impl ReadEntry for NonSolidReadEntry { - type Reader = EntryReader>>; - #[inline] fn header(&self) -> &EntryHeader { &self.header @@ -358,13 +363,13 @@ impl ReadEntry for NonSolidReadEntry { } #[inline] - fn into_reader(self, option: ReadOption) -> io::Result { + fn into_reader(self, option: ReadOption) -> io::Result { self.reader(option.password.as_deref()) } } impl NonSolidReadEntry { - fn reader(self, password: Option<&str>) -> io::Result>>> { + fn reader(self, password: Option<&str>) -> io::Result { let raw_data_reader = io::Cursor::new(self.data); let decrypt_reader = decrypt_reader( raw_data_reader, @@ -374,7 +379,7 @@ impl NonSolidReadEntry { password, )?; let reader = decompress_reader(decrypt_reader, self.header.compression)?; - Ok(EntryReader(reader)) + Ok(EntryDataReader(EntryReader(reader))) } }