mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Impl new fn helpers::download_and_extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
c3b5cb11c2
commit
784d1f0bf6
1 changed files with 10 additions and 1 deletions
|
@ -53,6 +53,15 @@ 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 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> {
|
||||
debug!("Downloading from: '{url}'");
|
||||
|
||||
let resp = reqwest::get(url.clone())
|
||||
|
@ -68,7 +77,7 @@ pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), Binstall
|
|||
debug!("Downloading to file: '{}'", path.display());
|
||||
|
||||
let mut bytes_stream = resp.bytes_stream();
|
||||
let mut writer = AsyncFileWriter::new(path, PkgFmt::Bin);
|
||||
let mut writer = AsyncFileWriter::new(path, fmt);
|
||||
|
||||
while let Some(res) = bytes_stream.next().await {
|
||||
writer.write(res?).await?;
|
||||
|
|
Loading…
Add table
Reference in a new issue