Struct async_mtzip::ZipArchive

source ·
pub struct ZipArchive {
    pub jobs_queue: Vec<ZipJob>,
    /* private fields */
}
Expand description

Structure that holds the current state of ZIP archive creation.

§Lifetimes

Because some of the methods allow supplying borrowed data, the lifetimes are used to indicate that Self borrows them. If you only provide owned data, such as Vec<u8> or PathBuf, you won’t have to worry about lifetimes and can simply use 'static, if you ever need to specify them in your code.

Fields§

§jobs_queue: Vec<ZipJob>

Implementations§

source§

impl ZipArchive

source

pub fn new() -> Self

Create an empty ZipArchive

source

pub fn add_file_from_fs( &mut self, fs_path: PathBuf, archived_path: String, compression_level: Option<CompressionLevel>, compression_type: Option<CompressionType> ) -> ZipJob

Add file from filesystem.

Opens the file and reads data from it when compress is called.

Default value for compression_type is Deflate.

compression_level is ignored when CompressionType::Stored is used. Default value is CompressionLevel::best.

This method does not allow setting ExtraFields manually and instead uses the filesystem to obtain them.

source

pub async fn add_file_from_fs_with_tokio( &mut self, fs_path: PathBuf, archived_path: String, compression_level: Option<CompressionLevel>, compression_type: Option<CompressionType> )

source

pub fn add_directory<P: Fn(u64, u64)>( &mut self, archived_path: String, attributes: Option<u16>, zip_listener: Arc<Mutex<P>> ) -> ZipJob

Add file with data from memory.

The data can be either borrowed or owned by the ZipArchive struct to avoid lifetime hell.

Default value for compression_type is Deflate.

compression_level is ignored when CompressionType::Stored is used. Default value is CompressionLevel::best.

extra_fields parameter allows setting extra attributes. Currently it supports NTFS and UNIX filesystem attributes, see more in ExtraFields description. Add a file with data from a reader.

This method takes any type implementing Read and allows it to have borrowed data ('r)

Default value for compression_type is Deflate.

compression_level is ignored when CompressionType::Stored is used. Default value is CompressionLevel::best.

extra_fields parameter allows setting extra attributes. Currently it supports NTFS and UNIX filesystem attributes, see more in ExtraFields description. Add a directory entry.

All directories in the tree should be added. This method does not asssociate any filesystem properties to the entry.

source

pub fn add_directory_with_tokio( &mut self, archived_path: String, attributes: Option<u16> ) -> ZipJob

source

pub fn compress<P: Fn(u64, u64) + Send>(&mut self, zip_listener: Arc<Mutex<P>>)

Add a directory entry.

All directories in the tree should be added. Use this method if you want to manually set filesystem properties of the directory.

extra_fields parameter allows setting extra attributes. Currently it supports NTFS and UNIX filesystem attributes, see more in ExtraFields description. Add a directory entry.

All directories in the tree should be added. This method will take the metadata from filesystem and add it to the entry in the zip file. Compress contents. Will be done automatically on write call if files were added between last compression and write call. Automatically chooses amount of threads to use based on how much are available.

source

pub fn compress_with_threads<P: Fn(u64, u64) + Send>( &mut self, threads: usize, zip_listener: Arc<Mutex<P>> )

Compress contents. Will be done automatically on write_with_threads call if files were added between last compression and write. Allows specifying amount of threads that will be used.

Example of getting amount of threads that this library uses in compress:

let threads = std::thread::available_parallelism()
    .map(NonZeroUsize::get)
    .unwrap_or(1);

zipper.compress_with_threads(threads);
source

pub fn write<W: Write + Seek, P: Fn(u64, u64) + Send>( &mut self, writer: &mut W, zip_listener: Arc<Mutex<P>> ) -> Result<()>

Write compressed data to a writer (usually a file). Executes compress if files were added between last compress call and this call. Automatically chooses the amount of threads cpu has.

source

pub async fn write_with_tokio<W: AsyncWrite + AsyncSeek + Unpin>( &mut self, writer: &mut W, jobs: Arc<Mutex<Vec<ZipJob>>>, process: Option<Sender<u64>> ) -> Result<()>

source

pub fn write_with_threads<W: Write + Seek, P: Fn(u64, u64) + Send>( &mut self, writer: &mut W, threads: usize, zip_listener: Arc<Mutex<P>> ) -> Result<()>

Write compressed data to a writer (usually a file). Executes compress_with_threads if files were added between last compress call and this call. Allows specifying amount of threads that will be used.

Example of getting amount of threads that this library uses in write:

let threads = std::thread::available_parallelism()
    .map(NonZeroUsize::get)
    .unwrap_or(1);

zipper.compress_with_threads(threads);
source

pub async fn write_with_threads_with_tokio<W: AsyncWrite + AsyncSeek + Unpin>( &mut self, writer: &mut W, threads: usize, jobs: Arc<Mutex<Vec<ZipJob>>>, tx: Option<Sender<u64>> ) -> Result<()>

source§

impl ZipArchive

source

pub fn compress_with_rayon(&mut self)

Compress contents and use rayon for parallelism.

Uses whatever thread pool this function is executed in.

If you want to limit the amount of threads to be used, use rayon::ThreadPoolBuilder::num_threads and either set it as a global pool, or rayon::ThreadPool::install the call to this method in it.

source

pub fn write_with_rayon<W: Write + Seek + Send>( &mut self, writer: &mut W ) -> Result<()>

Write the contents to a writer.

This method uses teh same thread logic as Self::compress_with_rayon, refer to its documentation for details on how to control the parallelism and thread allocation.

Trait Implementations§

source§

impl Debug for ZipArchive

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ZipArchive

source§

fn default() -> ZipArchive

Returns the “default value” for a type. Read more

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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

§

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.