pub struct Archive { /* private fields */ }
Expand description
Archive
represents an archive file which can be processed.
Implementations§
Source§impl Archive
impl Archive
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Self
pub fn open<P: AsRef<Path>>(path: P) -> Self
open
creates a default Archive
configuration from the given path.
§Note:
It handles the path lazily. So no error will occur until operations are operated on the archive.
Sourcepub fn block_size(&mut self, block_size: usize) -> &mut Self
pub fn block_size(&mut self, block_size: usize) -> &mut Self
block_size
sets the size limit for every block reading from the archive.
The block size is represented in bytes.
§Note:
The content from archives is read block by block. Setting the block size will increase/decrease the time and content of reading each block.
Sourcepub fn reset_block_size(&mut self) -> &mut Self
pub fn reset_block_size(&mut self) -> &mut Self
reset_block_size
resets the block size back to the default value (1024 * 1024).
Sourcepub fn decoder(
&mut self,
function: fn(&[u8]) -> Option<Cow<'_, str>>,
) -> &mut Self
pub fn decoder( &mut self, function: fn(&[u8]) -> Option<Cow<'_, str>>, ) -> &mut Self
decoding_fn
sets a function as the decoder.
§Note:
A decoder is a function that converts a series of bytes into a proper string.
In the case where the conversion failed, it should return None
.
Sourcepub fn reset_decoder(&mut self) -> &mut Self
pub fn reset_decoder(&mut self) -> &mut Self
reset_decoder
resets the decoder back to the default decoder.
The default decoder converts the bytes into a UTF-8 encoded string.
Any inconvertible characters will be replaced with a
U+FFFD REPLACEMENT CHARACTER, which looks like this: �.
Sourcepub fn try_password(&mut self, passwd: impl Into<String>) -> &mut Self
pub fn try_password(&mut self, passwd: impl Into<String>) -> &mut Self
try_password
adds a potential password to try during the unpacking.
Calling this method multiple times will add multiple passwords to be tried.
Source§impl Archive
impl Archive
Sourcepub fn list_file_names(
&self,
) -> Result<impl Iterator<Item = Result<String>> + Send>
pub fn list_file_names( &self, ) -> Result<impl Iterator<Item = Result<String>> + Send>
list_file_names
return an iterator of file names extracted from the archive.
The file names are decoded using the decoder.
Sourcepub fn read_file<W: Write>(&self, file_name: &str, output: W) -> Result<usize>
pub fn read_file<W: Write>(&self, file_name: &str, output: W) -> Result<usize>
read_file
reads the content of a file into the given output.
It also returns the total number of bytes read.
§Note
Passwords need to be set before calling this function if the archive is encrypted.
Sourcepub fn read_file_by_block(
&self,
file_name: &str,
) -> Result<impl Iterator<Item = Result<Box<[u8]>>> + Send + use<>>
pub fn read_file_by_block( &self, file_name: &str, ) -> Result<impl Iterator<Item = Result<Box<[u8]>>> + Send + use<>>
read_file_by_block
reads the content of a file
and returns an iterator of the blocks.
§Note
Passwords need to be set before calling this function if the archive is encrypted.
Sourcepub fn entries<F>(&self, process: F) -> Result<()>
pub fn entries<F>(&self, process: F) -> Result<()>
entries
iterates through each file / dir in the archive
and passes the mutable references of the entries to the process closure.
Using the functions provided on the Entry
object,
one can get two things from each entry:
- Name
- Content
§Note
Passwords need to be set before calling this function if the archive is encrypted.