Simplify extract_tar_based_stream_and_visit

Rm unused param `path` and the unnecessary
`fs::create_dir_all` since the tar will not be extracted to disk.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-12 17:05:21 +10:00
parent 17fcac7e63
commit e376b71cf4
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 3 additions and 9 deletions

View file

@ -109,7 +109,7 @@ pub async fn download_tar_based_and_visit<
let stream = resp.bytes_stream(); let stream = resp.bytes_stream();
let visitor = extract_tar_based_stream_and_visit(stream, path, fmt, visitor).await?; let visitor = extract_tar_based_stream_and_visit(stream, fmt, visitor).await?;
debug!("Download OK, written to file: '{}'", path.display()); debug!("Download OK, written to file: '{}'", path.display());

View file

@ -233,21 +233,15 @@ where
pub async fn extract_tar_based_stream_and_visit<V: TarEntriesVisitor + Debug + Send + 'static, E>( pub async fn extract_tar_based_stream_and_visit<V: TarEntriesVisitor + Debug + Send + 'static, E>(
stream: impl Stream<Item = Result<Bytes, E>> + Unpin, stream: impl Stream<Item = Result<Bytes, E>> + Unpin,
output: &Path,
fmt: TarBasedFmt, fmt: TarBasedFmt,
mut visitor: V, mut visitor: V,
) -> Result<V, BinstallError> ) -> Result<V, BinstallError>
where where
BinstallError: From<E>, BinstallError: From<E>,
{ {
let path = output.to_owned();
extract_impl(stream, move |mut rx| { extract_impl(stream, move |mut rx| {
fs::create_dir_all(path.parent().unwrap())?; extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, Op::Visit(&mut visitor))
.map(|_| visitor)
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, Op::Visit(&mut visitor))?;
Ok(visitor)
}) })
.await .await
} }