Expand description
§bg3rustpaklib
A Rust library for reading and extracting Baldur’s Gate 3 PAK files.
This library provides functionality similar to lslib for working with Larian Studios’ PAK (LSPK) archive format.
§Features
- Read PAK files (versions 15, 16, 18 for BG3)
- List and search files within packages
- Extract individual files or entire packages
- Support for LZ4 and Zstd compression
- Support for solid archives
- Optional async API (enable
asyncfeature)
§Example
use bg3rustpaklib::{Package, PackageSearch};
fn main() -> bg3rustpaklib::Result<()> {
// Open a PAK file
let package = Package::open("Game.pak")?;
// Get package metadata
let metadata = package.metadata();
println!("Package version: {}", metadata.version);
println!("File count: {}", metadata.file_count);
// List all files
for file in package.files() {
println!("{} ({} bytes)", file.name(), file.size());
}
// Find files by pattern
let lsf_files = package.find("**/*.lsf");
println!("Found {} .lsf files", lsf_files.len());
// Extract a specific file
if let Some(file) = package.get("Public/Game/GUI/Assets/Tooltips/tooltip.lsf") {
let contents = package.read_file(file)?;
println!("File size: {} bytes", contents.len());
}
// Extract all files to a directory
package.extract_all("output/")?;
Ok(())
}§Async Support
Enable the async feature to use async APIs:
[dependencies]
bg3rustpaklib = { version = "0.1", features = ["async"] }ⓘ
use bg3rustpaklib::AsyncPackage;
#[tokio::main]
async fn main() -> bg3rustpaklib::Result<()> {
let package = AsyncPackage::open("Game.pak").await?;
let metadata = package.metadata().await;
println!("File count: {}", metadata.file_count);
Ok(())
}Modules§
- loca
- Localization file support for Larian Studios games.
Structs§
- File
Filter - A file filter that can be applied during extraction.
- Package
- An opened PAK package.
- Package
Builder - Builder for creating new PAK packages.
- Package
Builder Options - Options for building a PAK package.
- Package
File Entry - A file entry to be added to a package.
- Package
Flags - Package flags that control archive behavior.
- Package
Header - Common package header information extracted from version-specific headers.
- Package
Metadata - Metadata about a package.
- Packaged
File - A packaged file that can be extracted.
Enums§
- Compression
Method - Compression methods used in PAK files.
- Package
Version - PAK file format versions.
- PakError
- Errors that can occur when working with PAK files.
Constants§
- SIGNATURE
- The LSPK package signature.
Traits§
- Package
Search - Extension trait for searching within packages.
Functions§
- get_
package_ flags - Reads the flags value from an existing PAK file header.
- get_
package_ priority - Reads the priority value from an existing PAK file header.
Type Aliases§
- Result
- Result type alias for PAK operations.