Refactor: Abstract away AsyncExtracter by new fn

`extract_archive_stream`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-09 22:28:48 +10:00
parent 00242a40c6
commit cadf045d0a
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 33 additions and 14 deletions

View file

@ -5,7 +5,6 @@ use std::{
};
use cargo_toml::Manifest;
use futures_util::stream::StreamExt;
use log::{debug, info};
use reqwest::Method;
use serde::Serialize;
@ -15,7 +14,7 @@ use url::Url;
use crate::{BinstallError, Meta, PkgFmt};
mod async_extracter;
pub use async_extracter::AsyncExtracter;
pub use async_extracter::extract_archive_stream;
mod auto_abort_join_handle;
pub use auto_abort_join_handle::AutoAbortJoinHandle;
@ -70,14 +69,7 @@ pub async fn download_and_extract<P: AsRef<Path>, const N: usize>(
let path = path.as_ref();
debug!("Downloading to file: '{}'", path.display());
let mut bytes_stream = resp.bytes_stream();
let mut extracter = AsyncExtracter::new(path, fmt, desired_outputs);
while let Some(res) = bytes_stream.next().await {
extracter.feed(res?).await?;
}
extracter.done().await?;
extract_archive_stream(resp.bytes_stream(), path, fmt, desired_outputs).await?;
debug!("Download OK, written to file: '{}'", path.display());