Refactor: Mv TarEntriesVisitor to mod async_extracter

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-13 01:14:22 +10:00
parent 467f7f6834
commit 2091345ce0
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
3 changed files with 13 additions and 14 deletions

View file

@ -22,7 +22,6 @@ mod ui_thread;
pub use ui_thread::UIThread;
mod extracter;
pub use extracter::TarEntriesVisitor;
mod readable_rx;

View file

@ -232,6 +232,18 @@ where
.await
}
/// Visitor must iterate over all entries.
/// Entires can be in arbitary order.
pub trait TarEntriesVisitor {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError>;
}
impl<V: TarEntriesVisitor> TarEntriesVisitor for &mut V {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError> {
(*self).visit(entries)
}
}
pub async fn extract_tar_based_stream_and_visit<V: TarEntriesVisitor + Debug + Send + 'static, E>(
stream: impl Stream<Item = Result<Bytes, E>> + Unpin,
fmt: TarBasedFmt,

View file

@ -4,25 +4,13 @@ use std::path::Path;
use flate2::bufread::GzDecoder;
use log::debug;
use tar::{Archive, Entries};
use tar::Archive;
use xz2::bufread::XzDecoder;
use zip::read::ZipArchive;
use zstd::stream::Decoder as ZstdDecoder;
use crate::{BinstallError, TarBasedFmt};
/// Visitor must iterate over all entries.
/// Entires can be in arbitary order.
pub trait TarEntriesVisitor {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError>;
}
impl<V: TarEntriesVisitor> TarEntriesVisitor for &mut V {
fn visit<R: Read>(&mut self, entries: Entries<'_, R>) -> Result<(), BinstallError> {
(*self).visit(entries)
}
}
pub(super) fn create_tar_decoder(
dat: impl BufRead + 'static,
fmt: TarBasedFmt,