pub struct ParallelArchive { /* private fields */ }Expand description
A thread-safe wrapper around an MPQ archive for parallel operations
ParallelArchive enables concurrent reads from a single MPQ archive by
giving each thread its own file handle. This avoids seek conflicts that
would occur with a shared file handle.
§Examples
use wow_mpq::single_archive_parallel::ParallelArchive;
let archive = ParallelArchive::open("data.mpq")?;
// Extract multiple files in parallel
let files = vec!["file1.txt", "file2.txt", "file3.txt"];
let results = archive.extract_files_parallel(&files)?;
for (filename, data) in results {
println!("{}: {} bytes", filename, data.len());
}Implementations§
Source§impl ParallelArchive
impl ParallelArchive
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open an MPQ archive for parallel processing
This caches the file list upfront to enable efficient parallel operations.
Sourcepub fn extract_files_parallel(
&self,
filenames: &[&str],
) -> Result<Vec<(String, Vec<u8>)>>
pub fn extract_files_parallel( &self, filenames: &[&str], ) -> Result<Vec<(String, Vec<u8>)>>
Extract multiple files from the archive in parallel
Each file is extracted in a separate thread with its own file handle. This allows true parallel I/O without seek conflicts.
§Returns
A vector of (filename, data) tuples in the same order as the input
Sourcepub fn extract_matching_parallel<F>(
&self,
predicate: F,
) -> Result<Vec<(String, Vec<u8>)>>
pub fn extract_matching_parallel<F>( &self, predicate: F, ) -> Result<Vec<(String, Vec<u8>)>>
Extract files matching a predicate in parallel
This method lists all files in the archive and extracts those that match the given predicate function.
Sourcepub fn process_files_parallel<F, T>(
&self,
filenames: &[&str],
processor: F,
) -> Result<Vec<T>>
pub fn process_files_parallel<F, T>( &self, filenames: &[&str], processor: F, ) -> Result<Vec<T>>
Process files in parallel with a custom function
This is the most flexible method, allowing custom processing of each file.
Sourcepub fn read_file_with_new_handle(&self, filename: &str) -> Result<Vec<u8>>
pub fn read_file_with_new_handle(&self, filename: &str) -> Result<Vec<u8>>
Read a file using a new file handle
This is the core method that enables parallel reads. Each call opens a new file handle, avoiding conflicts with other threads.
Sourcepub fn list_files(&self) -> &[String]
pub fn list_files(&self) -> &[String]
Get the cached file list
Sourcepub fn thread_count(&self) -> usize
pub fn thread_count(&self) -> usize
Get the number of worker threads that will be used
Sourcepub fn extract_files_batched(
&self,
filenames: &[&str],
batch_size: usize,
) -> Result<Vec<(String, Vec<u8>)>>
pub fn extract_files_batched( &self, filenames: &[&str], batch_size: usize, ) -> Result<Vec<(String, Vec<u8>)>>
Extract files in batches for better performance with many small files
When extracting many small files, the overhead of opening file handles can dominate. This method processes files in batches per thread.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ParallelArchive
impl RefUnwindSafe for ParallelArchive
impl Send for ParallelArchive
impl Sync for ParallelArchive
impl Unpin for ParallelArchive
impl UnsafeUnpin for ParallelArchive
impl UnwindSafe for ParallelArchive
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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