Valve Pak (VPK) - Valve Pak File Library and CLI Tool
A Rust library and command-line tool for reading, writing, and manipulating Valve Pak (VPK) files used by Valve's Source engine games.
Features
- Full VPK Format Support: Both VPK v1 and v2 formats
- Unified API: Single struct handles both reading and writing operations
- Checksum Verification: MD5 checksum verification for VPK v2 files
- High Performance: Efficient I/O with buffered readers/writers and streaming
- Memory Safe: Written in Rust with comprehensive error handling
- CLI Tool: Complete command-line interface for common operations
- File-like Access: VPKFile implements standard Read/Seek traits
Installation
From Source
The compiled binary will be available at target/release/valve_pak.
As a Library
Add to your Cargo.toml:
CLI Usage
Pack a directory into a VPK file
Example:
Unpack a VPK file to a directory
Example:
List files in a VPK
Examples:
Verify VPK checksums and file integrity
Example:
Extract a single file from VPK
Example:
Library Usage
Basic Operations
use ;
Creating VPK files
use ;
File Operations
use ;
use ;
Error Handling
use ;
VPK Format Support
Version 1 (V1)
- Basic file tree structure
- CRC32 checksums for individual files
- No global checksums
Version 2 (V2)
- Extended header with metadata
- MD5 checksums for entire archive
- Support for chunk hashes
- Backward compatible with V1
Performance
The library is optimized for performance:
- Streaming I/O: Uses buffered readers/writers for efficient file operations
- Lazy Loading: File tree is loaded on demand when needed
- Memory Efficient: Large files are streamed rather than loaded entirely into memory
- Zero-Copy: Minimal data copying during read operations
Error Handling
All operations return Result<T> types with descriptive error messages using the anyhow crate. Errors include full context chains to help with debugging.
Testing
Run the test suite:
Run tests with output:
Dependencies
anyhow- Error handling with contextclap- Command line argument parsingmd5- MD5 checksum calculation (VPK v2)crc32fast- Fast CRC32 calculationwalkdir- Recursive directory traversal
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request