Move internal details of download to be internal to download (#314)

This commit is contained in:
Félix Saparelli 2022-08-31 12:10:03 +12:00 committed by GitHub
parent f38c1e73c3
commit 480ea19462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 16 deletions

View file

@ -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,
}; };

View file

@ -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;

View file

@ -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,

View file

@ -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

View file

@ -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)?;

View file

@ -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,