Struct Archive

Source
pub struct Archive { /* private fields */ }
Expand description

Archive represents an archive file which can be processed.

Implementations§

Source§

impl Archive

Source

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.

Source

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.

Source

pub fn reset_block_size(&mut self) -> &mut Self

reset_block_size resets the block size back to the default value (1024 * 1024).

Source

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.

Source

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: �.

Source

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

Source

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.

Source

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.

Source

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.

Source

pub fn entries<F>(&self, process: F) -> Result<()>
where F: FnMut(Entry<'_>) -> 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:

  1. Name
  2. Content
§Note

Passwords need to be set before calling this function if the archive is encrypted.

Source§

impl Archive

Source

pub fn path(&self) -> &Path

path returns the archive file path.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.