Skip to main content

Storage

Struct Storage 

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

RAII wrapper for MPQ archive access

Provides full CRUD operations on MPQ archives. Modifications are held in a virtual overlay until save() is called, which writes a complete new archive atomically (write to temp file, then rename).

All public methods are thread-safe: read operations acquire a shared lock; write and persist operations acquire an exclusive lock.

Implementations§

Source§

impl Storage

Source

pub fn open(path: &str, pool: Option<&HostWorkerPool>) -> Option<Storage>

Open an existing MPQ archive. Memory-maps the file and parses tables. @param path Path to the .mpq file. @param pool Optional WorkerPool for parallel compress/decompress (non-owning). @return A valid Storage, or std::nullopt on failure.

Source

pub fn create( opts: &CreateOptions, pool: Option<&HostWorkerPool>, ) -> Option<Storage>

Create a new empty archive in memory. No file on disk until save(path).

Source

pub fn close(&mut self)

Release all resources. Same effect as letting the Storage go out of scope.

Source

pub fn read_file(&self, name: &str) -> Option<Bytes>

Read a file from the archive. Checks the overlay first, then the source archive. @return File contents, or std::nullopt if not found or deleted.

Source

pub fn read_file_name_locale(&self, name: &str, locale: u16) -> Option<Bytes>

Read a file with a specific locale.

Source

pub fn file_exists(&self, name: &str) -> bool

Check if a file exists in the archive (including overlay).

Source

pub fn file_info(&self, name: &str) -> Option<FileInfo>

Get information about a file.

Source

pub fn archive_info(&self) -> Option<ArchiveInfo>

Get summary information about the archive.

Source

pub fn list_files(&self) -> Vec<String>

List all known filenames (from listfile + overlay additions − deletions).

Source

pub fn write_file( &mut self, name: &[u8], data: &[u8], opts: &WriteOptions, ) -> bool

Write or overwrite a file. Data is held in overlay until save(). @return true on success, false if the hash table is full.

Source

pub fn delete_file(&mut self, name: &str) -> bool

Delete a file from the archive. @return true if the file was found (in source or overlay), false otherwise.

Source

pub fn save(&mut self) -> bool

Save the archive to its original path (temp file + atomic rename). @return false if this Storage was created via create() with no prior save(path).

Source

pub fn save_path(&mut self, path: &str) -> bool

Save the archive to a specific path. After saving, the new file becomes the source archive and the overlay is cleared.

Trait Implementations§

Source§

impl Debug for Storage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Storage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Storage

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.