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.
'd
is the lifetime of borrowed data added viaadd_file_from_memory
'p
is the lifetime of borrowedPath
s used inadd_file_from_fs
'r
is the lifetime of of borrowed data in readers supplied toadd_file_from_reader
Fields§
§jobs_queue: Vec<ZipJob>
Implementations§
source§impl ZipArchive
impl ZipArchive
sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty ZipArchive
sourcepub fn add_file_from_fs(
&mut self,
fs_path: PathBuf,
archived_path: String,
compression_level: Option<CompressionLevel>,
compression_type: Option<CompressionType>
) -> ZipJob
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.
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> )
sourcepub fn add_directory<P: Fn(u64, u64)>(
&mut self,
archived_path: String,
attributes: Option<u16>,
zip_listener: Arc<Mutex<P>>
) -> ZipJob
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.
pub fn add_directory_with_tokio( &mut self, archived_path: String, attributes: Option<u16> ) -> ZipJob
sourcepub fn compress<P: Fn(u64, u64) + Send>(&mut self, zip_listener: Arc<Mutex<P>>)
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.
sourcepub fn compress_with_threads<P: Fn(u64, u64) + Send>(
&mut self,
threads: usize,
zip_listener: Arc<Mutex<P>>
)
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);
sourcepub fn write<W: Write + Seek, P: Fn(u64, u64) + Send>(
&mut self,
writer: &mut W,
zip_listener: Arc<Mutex<P>>
) -> Result<()>
pub fn write<W: Write + Seek, P: Fn(u64, u64) + Send>( &mut self, writer: &mut W, zip_listener: Arc<Mutex<P>> ) -> Result<()>
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<()>
sourcepub 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<()>
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);
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
impl ZipArchive
sourcepub fn compress_with_rayon(&mut self)
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.
sourcepub fn write_with_rayon<W: Write + Seek + Send>(
&mut self,
writer: &mut W
) -> Result<()>
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
impl Debug for ZipArchive
source§impl Default for ZipArchive
impl Default for ZipArchive
source§fn default() -> ZipArchive
fn default() -> ZipArchive
Auto Trait Implementations§
impl Freeze for ZipArchive
impl RefUnwindSafe for ZipArchive
impl Send for ZipArchive
impl Sync for ZipArchive
impl Unpin for ZipArchive
impl UnwindSafe for ZipArchive
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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