mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 12:10:02 +00:00
Use untar
in extract_compressed_from_readable
So that we can specify the files we want to extract to avoid io and save disk usage. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
be5e8616a2
commit
72983e4113
3 changed files with 41 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
fs,
|
||||
io::{stderr, stdin, Write},
|
||||
path::{Path, PathBuf},
|
||||
|
@ -53,14 +54,19 @@ pub async fn remote_exists(url: Url, method: Method) -> Result<bool, BinstallErr
|
|||
/// Download a file from the provided URL to the provided path
|
||||
pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), BinstallError> {
|
||||
let url = Url::parse(url)?;
|
||||
download_and_extract(url, PkgFmt::Bin, path.as_ref()).await
|
||||
download_and_extract::<_, 0>(url, PkgFmt::Bin, path.as_ref(), None).await
|
||||
}
|
||||
|
||||
/// Download a file from the provided URL and extract it to the provided path
|
||||
pub async fn download_and_extract<P: AsRef<Path>>(
|
||||
///
|
||||
/// * `desired_outputs - If Some(_) and `fmt` is not `PkgFmt::Bin` or
|
||||
/// `PkgFmt::Zip`, then it will filter the tar and only extract files
|
||||
/// specified in it.
|
||||
pub async fn download_and_extract<P: AsRef<Path>, const N: usize>(
|
||||
url: Url,
|
||||
fmt: PkgFmt,
|
||||
path: P,
|
||||
desired_outputs: Option<[Cow<'static, Path>; N]>,
|
||||
) -> Result<(), BinstallError> {
|
||||
debug!("Downloading from: '{url}'");
|
||||
|
||||
|
@ -77,7 +83,7 @@ pub async fn download_and_extract<P: AsRef<Path>>(
|
|||
debug!("Downloading to file: '{}'", path.display());
|
||||
|
||||
let mut bytes_stream = resp.bytes_stream();
|
||||
let mut writer = AsyncFileWriter::new(path, fmt);
|
||||
let mut writer = AsyncFileWriter::new(path, fmt, desired_outputs);
|
||||
|
||||
while let Some(res) = bytes_stream.next().await {
|
||||
writer.write(res?).await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue