| Crates.io | mpq-rs |
| lib.rs | mpq-rs |
| version | 0.1.0 |
| created_at | 2025-10-15 21:00:44.376778+00 |
| updated_at | 2025-10-15 21:00:44.376778+00 |
| description | A pure-rust implementation of a MoPaQ archive reader and writer |
| homepage | |
| repository | https://github.com/WarRaft/mpq-rs |
| max_upload_size | |
| id | 1884951 |
| size | 61,495 |
mpq-rs is a pure-Rust implementation of the MoPaQ archive format used in Blizzard titles such as Warcraft III. The crate lets you inspect MPQ archives, extract files, and build new archives without relying on native libraries.
Read + Seek.Warning: the crate does not aim to support "protected" maps that intentionally violate the MPQ specification.
Add the dependency to your Cargo.toml:
[dependencies]
mpq-rs = { git = "https://github.com/WarRaft/mpq-rs" }
use std::fs::File;
use std::io::BufReader;
use mpq_rs::Archive;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("maps/example.w3x")?;
let mut archive = Archive::open(BufReader::new(file))?;
let script = archive.read_file("war3map.j")?;
println!("Map script size: {} bytes", script.len());
Ok(())
}
(listfile)use std::fs::File;
use std::io::BufReader;
use mpq_rs::Archive;
fn list_files(path: &str) -> Result<(), Box<dyn std::error::Error>> {
let file = File::open(path)?;
let mut archive = Archive::open(BufReader::new(file))?;
if let Some(entries) = archive.files() {
for entry in entries {
println!("{entry}");
}
} else {
println!("Archive does not contain (listfile)");
}
Ok(())
}
use std::io::Cursor;
use mpq_rs::{Creator, FileOptions};
fn build_archive() -> Result<Vec<u8>, Box<dyn std::error::Error>> {
let mut buffer = Cursor::new(Vec::new());
let mut creator = Creator::default();
creator.add_file(
"hello.txt",
"Greetings from MPQ!",
FileOptions {
encrypt: false,
compress: true,
adjust_key: false,
},
);
creator.write(&mut buffer)?;
Ok(buffer.into_inner())
}
Sample Warcraft III maps for experimentation can be found under test-data/maps.
cargo test