Skip to content
Draft

vpk0 #26

Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add support to the vpk0 format, courtesy of (tehzz)[https://github.com/tehzz/vpk0].

## [0.5.4] - 2024-12-15

### Fixed
Expand Down
20 changes: 18 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions c_bindings/include/crunch64/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef enum Crunch64Error {
Crunch64Error_OutOfBounds,
Crunch64Error_NullPointer,
Crunch64Error_InvalidCompressionLevel,
Crunch64Error_Vpk0,
} Crunch64Error;

#ifdef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum CompressionType {
Yaz0,
Mio0,
Gzip,
Vpk0,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -46,6 +47,7 @@ fn compress(args: &Args, bytes: &[u8]) -> Result<Box<[u8]>, Crunch64Error> {
CompressionType::Yaz0 => crunch64::yaz0::compress(bytes),
CompressionType::Mio0 => crunch64::mio0::compress(bytes),
CompressionType::Gzip => crunch64::gzip::compress(bytes, args.level, args.small_mem),
CompressionType::Vpk0 => crunch64::vpk0::compress(bytes),
// _ => Err(Crunch64Error::UnsupportedCompressionType),
}
}
Expand All @@ -55,6 +57,7 @@ fn decompress(args: &Args, bytes: &[u8]) -> Result<Box<[u8]>, Crunch64Error> {
CompressionType::Yay0 => crunch64::yay0::decompress(bytes),
CompressionType::Yaz0 => crunch64::yaz0::decompress(bytes),
CompressionType::Mio0 => crunch64::mio0::decompress(bytes),
CompressionType::Vpk0 => crunch64::vpk0::decompress(bytes),
_ => Err(Crunch64Error::UnsupportedCompressionType),
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ crate-type = ["lib", "staticlib", "cdylib"]
crc32fast = "1.4.2"
pyo3 = { version="0.23.5", features = ["extension-module"], optional = true }
thiserror = "1.0"
vpk0 = "0.8.2"

[dev-dependencies]
rstest = "0.18.2"
Expand Down
6 changes: 5 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod gzip;
pub mod mio0;
pub mod vpk0;
pub mod yay0;
pub mod yaz0;

Expand All @@ -14,7 +15,8 @@ use pyo3::prelude::*;

/* This needs to be in sync with the C equivalent at `crunch64/error.h` */
#[cfg_attr(feature = "c_bindings", repr(u32))]
#[derive(Copy, Clone, Debug, Error, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "c_bindings", derive(Copy))]
#[derive(Clone, Debug, Error, PartialEq, Eq, Hash)]
pub enum Crunch64Error {
#[error("Not an error")]
Okay,
Expand All @@ -36,6 +38,8 @@ pub enum Crunch64Error {
NullPointer,
#[error("Invalid compression level")]
InvalidCompressionLevel,
#[error("Failed to handle vpk0 data")]
Vpk0,
}

#[cfg(feature = "python_bindings")]
Expand Down
15 changes: 15 additions & 0 deletions lib/src/vpk0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::Crunch64Error;

pub fn compress(bytes: &[u8]) -> Result<Box<[u8]>, Crunch64Error> {
match vpk0::encode_bytes(bytes) {
Ok(bytes) => Ok(bytes.into_boxed_slice()),
Err(_) => Err(Crunch64Error::Vpk0),
}
}

pub fn decompress(bytes: &[u8]) -> Result<Box<[u8]>, Crunch64Error> {
match vpk0::decode_bytes(bytes) {
Ok(bytes) => Ok(bytes.into_boxed_slice()),
Err(_) => Err(Crunch64Error::Vpk0),
}
}
Loading