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
impl Storage
Sourcepub fn open(path: &str, pool: Option<&HostWorkerPool>) -> Option<Storage>
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.
Sourcepub fn create(
opts: &CreateOptions,
pool: Option<&HostWorkerPool>,
) -> Option<Storage>
pub fn create( opts: &CreateOptions, pool: Option<&HostWorkerPool>, ) -> Option<Storage>
Create a new empty archive in memory. No file on disk until save(path).
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Release all resources. Same effect as letting the Storage go out of scope.
Sourcepub fn read_file(&self, name: &str) -> Option<Bytes>
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.
Sourcepub fn read_file_name_locale(&self, name: &str, locale: u16) -> Option<Bytes>
pub fn read_file_name_locale(&self, name: &str, locale: u16) -> Option<Bytes>
Read a file with a specific locale.
Sourcepub fn file_exists(&self, name: &str) -> bool
pub fn file_exists(&self, name: &str) -> bool
Check if a file exists in the archive (including overlay).
Sourcepub fn archive_info(&self) -> Option<ArchiveInfo>
pub fn archive_info(&self) -> Option<ArchiveInfo>
Get summary information about the archive.
Sourcepub fn list_files(&self) -> Vec<String>
pub fn list_files(&self) -> Vec<String>
List all known filenames (from listfile + overlay additions − deletions).
Sourcepub fn write_file(
&mut self,
name: &[u8],
data: &[u8],
opts: &WriteOptions,
) -> bool
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.
Sourcepub fn delete_file(&mut self, name: &str) -> bool
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.