mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Move internal details of download to be internal to download (#314)
This commit is contained in:
parent
f38c1e73c3
commit
480ea19462
6 changed files with 11 additions and 16 deletions
|
@ -10,7 +10,7 @@ use tar::Entries;
|
||||||
|
|
||||||
use super::vfs::Vfs;
|
use super::vfs::Vfs;
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::BinstallError, helpers::async_extracter::TarEntriesVisitor,
|
errors::BinstallError, helpers::download::TarEntriesVisitor,
|
||||||
manifests::cargo_toml_binstall::Meta,
|
manifests::cargo_toml_binstall::Meta,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
pub mod async_extracter;
|
|
||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod extracter;
|
|
||||||
pub mod jobserver_client;
|
pub mod jobserver_client;
|
||||||
pub mod remote;
|
pub mod remote;
|
||||||
pub mod signal;
|
pub mod signal;
|
||||||
pub mod statics;
|
pub mod statics;
|
||||||
pub mod stream_readable;
|
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
|
|
|
@ -5,17 +5,16 @@ use reqwest::{Client, Url};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::BinstallError,
|
errors::BinstallError,
|
||||||
helpers::{
|
helpers::remote::create_request,
|
||||||
async_extracter::{
|
|
||||||
extract_bin, extract_tar_based_stream, extract_tar_based_stream_and_visit, extract_zip,
|
|
||||||
},
|
|
||||||
remote::create_request,
|
|
||||||
},
|
|
||||||
manifests::cargo_toml_binstall::{PkgFmt, PkgFmtDecomposed, TarBasedFmt},
|
manifests::cargo_toml_binstall::{PkgFmt, PkgFmtDecomposed, TarBasedFmt},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::async_extracter::TarEntriesVisitor;
|
pub use async_extracter::TarEntriesVisitor;
|
||||||
|
use async_extracter::*;
|
||||||
|
|
||||||
|
mod async_extracter;
|
||||||
|
mod extracter;
|
||||||
|
mod stream_readable;
|
||||||
/// 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>>(
|
pub async fn download_and_extract<P: AsRef<Path>>(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
|
|
|
@ -13,9 +13,8 @@ use tar::Entries;
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
use tokio::task::block_in_place;
|
use tokio::task::block_in_place;
|
||||||
|
|
||||||
use crate::{errors::BinstallError, manifests::cargo_toml_binstall::TarBasedFmt};
|
|
||||||
|
|
||||||
use super::{extracter::*, stream_readable::StreamReadable};
|
use super::{extracter::*, stream_readable::StreamReadable};
|
||||||
|
use crate::{errors::BinstallError, manifests::cargo_toml_binstall::TarBasedFmt};
|
||||||
|
|
||||||
pub async fn extract_bin<S, E>(stream: S, path: &Path) -> Result<(), BinstallError>
|
pub async fn extract_bin<S, E>(stream: S, path: &Path) -> Result<(), BinstallError>
|
||||||
where
|
where
|
|
@ -14,7 +14,7 @@ use zstd::stream::Decoder as ZstdDecoder;
|
||||||
|
|
||||||
use crate::{errors::BinstallError, manifests::cargo_toml_binstall::TarBasedFmt};
|
use crate::{errors::BinstallError, manifests::cargo_toml_binstall::TarBasedFmt};
|
||||||
|
|
||||||
pub(super) fn create_tar_decoder(
|
pub fn create_tar_decoder(
|
||||||
dat: impl BufRead + 'static,
|
dat: impl BufRead + 'static,
|
||||||
fmt: TarBasedFmt,
|
fmt: TarBasedFmt,
|
||||||
) -> io::Result<Archive<Box<dyn Read>>> {
|
) -> io::Result<Archive<Box<dyn Read>>> {
|
||||||
|
@ -36,7 +36,7 @@ pub(super) fn create_tar_decoder(
|
||||||
Ok(Archive::new(r))
|
Ok(Archive::new(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn unzip(dat: File, dst: &Path) -> Result<(), BinstallError> {
|
pub fn unzip(dat: File, dst: &Path) -> Result<(), BinstallError> {
|
||||||
debug!("Decompressing from zip archive to `{dst:?}`");
|
debug!("Decompressing from zip archive to `{dst:?}`");
|
||||||
|
|
||||||
let mut zip = ZipArchive::new(dat)?;
|
let mut zip = ZipArchive::new(dat)?;
|
|
@ -15,7 +15,7 @@ use crate::errors::BinstallError;
|
||||||
/// `tokio::task::{block_in_place, spawn_blocking}` or
|
/// `tokio::task::{block_in_place, spawn_blocking}` or
|
||||||
/// `std::thread::spawn`.
|
/// `std::thread::spawn`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct StreamReadable<S> {
|
pub struct StreamReadable<S> {
|
||||||
stream: S,
|
stream: S,
|
||||||
handle: Handle,
|
handle: Handle,
|
||||||
bytes: Bytes,
|
bytes: Bytes,
|
Loading…
Add table
Reference in a new issue