mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 12:10:02 +00:00
Refactor: Extract download_and_extract_with_filter
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
1d139324c7
commit
62be22256b
4 changed files with 18 additions and 6 deletions
|
@ -43,13 +43,26 @@ pub async fn remote_exists(url: Url, method: Method) -> Result<bool, BinstallErr
|
|||
Ok(req.status().is_success())
|
||||
}
|
||||
|
||||
/// Download a file from the provided URL and extract it to the provided path
|
||||
/// Download a file from the provided URL and extract it to the provided path.
|
||||
pub async fn download_and_extract<P: AsRef<Path>>(
|
||||
url: Url,
|
||||
fmt: PkgFmt,
|
||||
path: P,
|
||||
) -> Result<(), BinstallError> {
|
||||
download_and_extract_with_filter::<fn(&Path) -> bool, _>(url, fmt, path.as_ref(), None).await
|
||||
}
|
||||
|
||||
/// Download a file from the provided URL and extract part of it to
|
||||
/// the provided path.
|
||||
///
|
||||
/// * `filter` - If Some, then it will pass the path of the file to it
|
||||
/// and only extract ones which filter returns `true`.
|
||||
/// Note that this is a best-effort and it only works when `fmt`
|
||||
/// is not `PkgFmt::Bin` or `PkgFmt::Zip`.
|
||||
pub async fn download_and_extract<Filter: FnMut(&Path) -> bool + Send + 'static, P: AsRef<Path>>(
|
||||
pub async fn download_and_extract_with_filter<
|
||||
Filter: FnMut(&Path) -> bool + Send + 'static,
|
||||
P: AsRef<Path>,
|
||||
>(
|
||||
url: Url,
|
||||
fmt: PkgFmt,
|
||||
path: P,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue