Skip to main content

Crate bg3rustpaklib

Crate bg3rustpaklib 

Source
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 async feature)

§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§

FileFilter
A file filter that can be applied during extraction.
Package
An opened PAK package.
PackageBuilder
Builder for creating new PAK packages.
PackageBuilderOptions
Options for building a PAK package.
PackageFileEntry
A file entry to be added to a package.
PackageFlags
Package flags that control archive behavior.
PackageHeader
Common package header information extracted from version-specific headers.
PackageMetadata
Metadata about a package.
PackagedFile
A packaged file that can be extracted.

Enums§

CompressionMethod
Compression methods used in PAK files.
PackageVersion
PAK file format versions.
PakError
Errors that can occur when working with PAK files.

Constants§

SIGNATURE
The LSPK package signature.

Traits§

PackageSearch
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.