Struct archive_reader::Archive
source · 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 the path is used and proved to be problematic.
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:
Content from archives are 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 an UTF-8 encoded string.
Any inconvertible characters will be replaced with a
U+FFFD REPLACEMENT CHARACTER, which looks like this: �.
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.