Struct Archiver

Source
pub struct Archiver { /* private fields */ }
Expand description

Archiver struct.

You can use this struct and its methods to compress directories or files. For the detail example, see also archive function.

Implementations§

Source§

impl Archiver

Source

pub fn new() -> Self

Create a new Archiver instance. The initial number of threads is 1.

Source

pub fn set_destination<T: AsRef<Path>>(&mut self, dest: T)

Set the destination of compressed files. If the destination directory does not exist, it will create a new directory when the archive function is called.

Source

pub fn set_thread_count(&mut self, thread_count: u32)

Set for the number of threads.

Source

pub fn set_sender(&mut self, sender: Sender<String>)

Set the std::sync::mpsc::Sender to send messages whether compressing processes complete.

Source

pub fn set_format(&mut self, comp_format: Format)

Set the format of the file to be compressed with Format. For more information, see Format.

use zip_archive::{Archiver, Format};
let mut archiver = Archiver::new();
archiver.set_format(Format::_7z);
Source

pub fn set_format_str<T: ToString>(&mut self, comp_format_str: T)

Set the format of the file to be compressed with a string.

use zip_archive::Archiver;
let mut archiver = Archiver::new();
archiver.set_format_str("7z");
Source

pub fn push_from_iter<I>(&mut self, iter: I)
where I: Iterator, I::Item: AsRef<Path>,

Push all elements in givin iterator to the queue. It iterate through all elements and push it to the queue.

§Examples
use zip_archive::Archiver;

let mut archiver = Archiver::new();
archiver.push_from_iter(vec!["origin/dir1", "origin/dir2", "origin/dir3"].into_iter());
Source

pub fn push<T: AsRef<Path>>(&mut self, path: T)

Push a single directory to the queue.

§Examples
use zip_archive::Archiver;

let mut archiver = Archiver::new();
archiver.push("origin/dir1");
archiver.push("origin/dir2");
archiver.push("origin/dir3");
Source

pub fn archive(&self) -> Result<(), Box<dyn Error>>

Compress directories in the queue with multithread.

§Examples
use std::path::PathBuf;
use zip_archive::Archiver;

let origin = PathBuf::from("./origin");
let dest = PathBuf::from("./dest");
let thread_count = 4;

let mut archiver = Archiver::new();
archiver.push(origin);
archiver.set_destination(dest);
archiver.set_thread_count(thread_count);

match archiver.archive(){
    Ok(_) => (),
    Err(e) => println!("Cannot archive the directory! {}", e),
};

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.