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.
Sourcepub fn read_file_by_block(
&self,
file_name: &str,
) -> Result<impl Iterator<Item = Result<Box<[u8]>>> + Send>
pub fn read_file_by_block( &self, file_name: &str, ) -> Result<impl Iterator<Item = Result<Box<[u8]>>> + Send>
read_file_by_block reads the content of a file,
and returns an iterator of the blocks.