mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 12:10:02 +00:00
Refactor: Abstract away AsyncExtracter
by new fn
`extract_archive_stream` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
00242a40c6
commit
cadf045d0a
2 changed files with 33 additions and 14 deletions
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue