Rename AsyncFileWriter to AsyncExtracter

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-09 21:58:51 +10:00
parent e62775a9ec
commit 945687c281
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
3 changed files with 14 additions and 14 deletions

View file

@ -14,8 +14,8 @@ use url::Url;
use crate::{BinstallError, Meta, PkgFmt}; use crate::{BinstallError, Meta, PkgFmt};
mod async_file_writer; mod async_extracter;
pub use async_file_writer::AsyncFileWriter; pub use async_extracter::AsyncExtracter;
mod auto_abort_join_handle; mod auto_abort_join_handle;
pub use auto_abort_join_handle::AutoAbortJoinHandle; pub use auto_abort_join_handle::AutoAbortJoinHandle;
@ -71,13 +71,13 @@ pub async fn download_and_extract<P: AsRef<Path>, const N: usize>(
debug!("Downloading to file: '{}'", path.display()); debug!("Downloading to file: '{}'", path.display());
let mut bytes_stream = resp.bytes_stream(); let mut bytes_stream = resp.bytes_stream();
let mut writer = AsyncFileWriter::new(path, fmt, desired_outputs); let mut extracter = AsyncExtracter::new(path, fmt, desired_outputs);
while let Some(res) = bytes_stream.next().await { while let Some(res) = bytes_stream.next().await {
writer.write(res?).await?; extracter.write(res?).await?;
} }
writer.done().await?; extracter.done().await?;
debug!("Download OK, written to file: '{}'", path.display()); debug!("Download OK, written to file: '{}'", path.display());

View file

@ -20,14 +20,14 @@ pub(crate) enum Content {
} }
#[derive(Debug)] #[derive(Debug)]
struct AsyncFileWriterInner { struct AsyncExtracterInner {
/// Use AutoAbortJoinHandle so that the task /// Use AutoAbortJoinHandle so that the task
/// will be cancelled on failure. /// will be cancelled on failure.
handle: AutoAbortJoinHandle<Result<(), BinstallError>>, handle: AutoAbortJoinHandle<Result<(), BinstallError>>,
tx: mpsc::Sender<Content>, tx: mpsc::Sender<Content>,
} }
impl AsyncFileWriterInner { impl AsyncExtracterInner {
/// * `desired_outputs - If Some(_), then it will filter the tar /// * `desired_outputs - If Some(_), then it will filter the tar
/// and only extract files specified in it. /// and only extract files specified in it.
fn new<const N: usize>( fn new<const N: usize>(
@ -148,16 +148,16 @@ impl AsyncFileWriterInner {
} }
} }
/// AsyncFileWriter will pass the `Bytes` you give to another thread via /// AsyncExtracter will pass the `Bytes` you give to another thread via
/// a `mpsc` and decompress and unpack it if needed. /// a `mpsc` and decompress and unpack it if needed.
/// ///
/// # Cancellation /// # Cancellation
/// ///
/// AsyncFileWriter removes the file if `done` isn't called. /// AsyncExtracter removes the file if `done` isn't called.
#[derive(Debug)] #[derive(Debug)]
pub struct AsyncFileWriter(ScopeGuard<AsyncFileWriterInner, fn(AsyncFileWriterInner), Always>); pub struct AsyncExtracter(ScopeGuard<AsyncExtracterInner, fn(AsyncExtracterInner), Always>);
impl AsyncFileWriter { impl AsyncExtracter {
/// * `desired_outputs - If Some(_) and `fmt` is not `PkgFmt::Bin` or /// * `desired_outputs - If Some(_) and `fmt` is not `PkgFmt::Bin` or
/// `PkgFmt::Zip`, then it will filter the tar and only extract files /// `PkgFmt::Zip`, then it will filter the tar and only extract files
/// specified in it. /// specified in it.
@ -166,8 +166,8 @@ impl AsyncFileWriter {
fmt: PkgFmt, fmt: PkgFmt,
desired_outputs: Option<[Cow<'static, Path>; N]>, desired_outputs: Option<[Cow<'static, Path>; N]>,
) -> Self { ) -> Self {
let inner = AsyncFileWriterInner::new(path, fmt, desired_outputs); let inner = AsyncExtracterInner::new(path, fmt, desired_outputs);
Self(guard(inner, AsyncFileWriterInner::abort)) Self(guard(inner, AsyncExtracterInner::abort))
} }
/// Upon error, this writer shall not be reused. /// Upon error, this writer shall not be reused.

View file

@ -4,7 +4,7 @@ use std::io::{self, Read};
use bytes::{Buf, Bytes}; use bytes::{Buf, Bytes};
use tokio::sync::mpsc::Receiver; use tokio::sync::mpsc::Receiver;
use super::async_file_writer::Content; use super::async_extracter::Content;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct ReadableRx<'a> { pub(crate) struct ReadableRx<'a> {