Struct Archive

Source
pub struct Archive {
    pub entries: Vec<Entry>,
    /* private fields */
}

Fields§

§entries: Vec<Entry>

Implementations§

Source§

impl Archive

Source

pub fn new(file: File) -> Self

Creates a new archive file. The file signature is written to the beginning of the file. The file is truncated to 0 bytes.

Source

pub fn open(path: &str) -> Result<Self>

Opens an existing archive file for reading and writing. This will not overwrite the file, but append to it.

Source

pub fn open_file(file: File) -> Result<Self>

Opens an existing archive file for reading and writing. This will not overwrite the file, but append to it.

Source

pub const fn version(&self) -> u8

Retrieves the format version of the archive. This is the version of the archive format.

Source

pub fn set_compression_callback( &mut self, callback: CompressionFormatCallback, ) -> &mut Self

Sets the compression callback for the archive. This callback is called for each added file entry in the archive. The callback should return the compression format to use for the file.

Source

pub fn set_real_size_callback( &mut self, callback: Option<Arc<dyn Fn(&Path) -> u64 + Send + Sync + 'static>>, ) -> &mut Self

Sets the “real” size callback for the archive. This callback is called for each added file entry in the archive. The callback should return the “real” size of the file.

Source

pub fn add_directory( &mut self, path: &str, progress: ProgressCallback, ) -> Result<&mut Self>

Adds all files in the given directory to the archive. (including subdirectories) This will append the directory to the end of the archive, if this directory already exists, it will not be replaced.

After this function is called, the existing header will be trimmed to the end of the archive, then readded upon completion.

§Panics

This function will panic if any filename is not valid UTF-8 or longer than 255 bytes.

Source

pub fn entries(&self) -> &[Entry]

Returns the entries in the archive.

Source

pub fn into_entries(self) -> Vec<Entry>

Consumes the archive and returns the entries.

Source

pub fn write_file_entry( &mut self, reader: impl Read, size_real: Option<u64>, name: impl Into<String>, mode: EntryMode, mtime: SystemTime, owner: (u32, u32), compression: CompressionFormat, ) -> Result<Box<FileEntry>>

Writes a new file entry to the archive. This will NOT append the entry to the archive, it will write the content of the file to the archive and return the entry.

§Important

This function does not trim the end header or readd the end header, you will need to do that manually after calling this function.

Source

pub fn add_entries( &mut self, entries: Vec<DirEntry>, progress: ProgressCallback, ) -> Result<&mut Self>

Adds a single file entry to the archive. (including subdirectories) This will append the entry to the end of the archive, if this entry already exists, it will not be replaced.

After this function is called, the existing header will be trimmed to the end of the archive, then readded upon completion.

§Panics

This function will panic if any filename is not valid UTF-8 or longer than 255 bytes.

Source

pub fn find_archive_entry(&self, entry_name: &Path) -> Option<&Entry>

Finds an entry in the archive by name. Returns None if the entry is not found. The entry name is the path inside the archive. Example: “world/user/level.dat” would be a valid entry name.

Source

pub fn find_archive_entry_mut( &mut self, entry_name: &Path, ) -> Option<&mut Entry>

Finds an entry in the archive by name. Returns None if the entry is not found. The entry name is the path inside the archive. Example: “world/user/level.dat” would be a valid entry name.

Source

pub fn trim_end_header(&mut self) -> Result<()>

Source

pub fn write_end_header(&mut self) -> Result<()>

Trait Implementations§

Source§

impl Debug for Archive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.