Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethteck committed Dec 4, 2023
1 parent 90cc6b1 commit 2a23046
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub enum CompressionType {
}

impl CompressionType {
pub fn decompress(self: CompressionType, bytes: Vec<u8>) -> Vec<u8> {
pub fn decompress(self: CompressionType, bytes: &[u8]) -> Box<[u8]> {
match self {
CompressionType::Yay0 => decompress_yay0(bytes),
_ => panic!("Unsupported compression type: {:?}", self),
}
}

pub fn compress(self: CompressionType, bytes: Vec<u8>) -> Vec<u8> {
pub fn compress(self: CompressionType, bytes: &[u8]) -> Box<[u8]> {
match self {
CompressionType::Yay0 => compress_yay0(bytes),
_ => panic!("Unsupported compression type: {:?}", self),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
let file_magic: &[u8] = &file_bytes[0..4];

let out_bytes = match file_magic {
b"Yay0" => crunch64::CompressionType::Yay0.decompress(file_bytes),
b"Yay0" => crunch64::CompressionType::Yay0.decompress(file_bytes.as_slice()),
_ => {
panic!("File format not recognized - magic: {:?}", file_magic)
}
Expand Down
6 changes: 3 additions & 3 deletions src/yay0.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn decompress_yay0(bytes: Vec<u8>) -> Vec<u8> {
pub fn decompress_yay0(bytes: &[u8]) -> Box<[u8]> {
let decompressed_size = u32::from_be_bytes(bytes[4..8].try_into().unwrap());
let link_table_offset = u32::from_be_bytes(bytes[8..12].try_into().unwrap());
let chunk_offset = u32::from_be_bytes(bytes[12..16].try_into().unwrap());
Expand Down Expand Up @@ -56,9 +56,9 @@ pub fn decompress_yay0(bytes: Vec<u8>) -> Vec<u8> {
mask_bit_counter -= 1;
}

ret
ret.into_boxed_slice()
}

pub fn compress_yay0(_bytes: Vec<u8>) -> Vec<u8> {
pub fn compress_yay0(_bytes: &[u8]) -> Box<[u8]> {
panic!("Not implemented")
}

0 comments on commit 2a23046

Please sign in to comment.