Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit bcb2bf3
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Sat Dec 16 19:00:02 2023 +0100

    ci

commit ce2dc86
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Sat Dec 16 18:56:56 2023 +0100

    partial revert "bundle libs"

    This reverts commit a730259.

commit 0bf280f
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Sat Dec 16 18:52:19 2023 +0100

    resize buffer

commit ead4f11
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Sat Dec 16 18:41:47 2023 +0100

    fix file tests on mac 🤡

commit 0ac5eec
Author: Moritz Baron <r.fuzzo@gmail.com>
Date:   Fri Dec 15 18:23:11 2023 +0100

    ci

commit dab3f27
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Fri Dec 15 17:56:48 2023 +0100

    ci

commit 27f2a1b
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Fri Dec 15 17:55:03 2023 +0100

    ci

commit e329778
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Fri Dec 15 17:54:24 2023 +0100

    ci

commit a730259
Author: rfuzzo <r.fuzzo@gmail.com>
Date:   Fri Dec 15 17:49:29 2023 +0100

    bundle libs
  • Loading branch information
rfuzzo committed Dec 16, 2023
1 parent 1c1939c commit 9a41866
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 33 deletions.
11 changes: 11 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
23 changes: 10 additions & 13 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@ name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
check:
runs-on: windows-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]

steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'true'

- name: unzip resources
run: |
cd src
Expand-Archive -Path .\metadata-resources.zip -DestinationPath .\

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions-rs/cargo@v1
with:
command: build
- uses: actions-rs/cargo@v1
with:
command: test
- run: cargo build
- run: cargo test
8 changes: 4 additions & 4 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ impl FromReader for LxrsFooter {
// buffer is compressed
let mut compressed_buffer = vec![0; zsize as usize];
reader.read_exact(&mut compressed_buffer[..])?;
let mut output_buffer = vec![0; size as usize];
let result = decompress(compressed_buffer, &mut output_buffer);
let mut output_buffer = vec![];
let result = decompress(compressed_buffer, &mut output_buffer, size as usize);
assert_eq!(result as u32, size);

// read from buffer
Expand Down Expand Up @@ -378,8 +378,8 @@ fn decompress_segment<R: Read + Seek, W: Write>(
}
let mut compressed_buffer = vec![0; segment.z_size as usize - 8];
archive_reader.read_exact(&mut compressed_buffer[..])?;
let mut output_buffer = vec![0; size as usize];
let result = decompress(compressed_buffer, &mut output_buffer);
let mut output_buffer = vec![];
let result = decompress(compressed_buffer, &mut output_buffer, size as usize);
assert_eq!(result as u32, size);

// write
Expand Down
18 changes: 13 additions & 5 deletions src/kraken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@ pub enum CompressionLevel {
}

/// Decompresses a compressed buffer into another
pub fn decompress(compressed_buffer: Vec<u8>, output_buffer: &mut Vec<u8>) -> i32 {
pub fn decompress(compressed_buffer: Vec<u8>, output_buffer: &mut Vec<u8>, size: usize) -> i32 {
let mut buffer = vec![0; size * 2];
let result;

unsafe {
Kraken_Decompress(
result = Kraken_Decompress(
compressed_buffer.as_ptr(),
compressed_buffer.len() as i64,
output_buffer.as_mut_ptr(),
output_buffer.len() as i64,
)
buffer.as_mut_ptr(),
size as i64,
);

buffer.resize(result as usize, 0);
*output_buffer = buffer;
}

result
}

/// Compresses a buffer into another
Expand Down
47 changes: 36 additions & 11 deletions tests/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
#[cfg(test)]
mod tests {
use std::fs::create_dir_all;
use std::io::{self, Read};
use std::path::Path;
use std::time::Instant;
use std::{fs, path::PathBuf};

use red4lib::archive::write_archive;
use red4lib::sha1_hash_file;
use red4lib::{
archive::{extract_archive, Archive},
get_red4_hashes,
};
use red4lib::archive::*;
use red4lib::io::FromReader;
use red4lib::*;

#[test]
fn time_csv() {
Expand All @@ -26,6 +24,18 @@ mod tests {
println!("Execution time csv: {:?}", duration);
}

#[test]
fn read_srxl() {
let file_path = PathBuf::from("tests").join("srxl.bin");
let mut file = fs::File::open(file_path).expect("Could not open file");
let mut buffer: Vec<u8> = vec![];
file.read_to_end(&mut buffer).expect("Could not read file");

let mut cursor = io::Cursor::new(&buffer);

let _srxl = LxrsFooter::from_reader(&mut cursor).unwrap();
}

#[test]
fn read_archive() {
let archive_path = PathBuf::from("tests").join("test1.archive");
Expand Down Expand Up @@ -71,8 +81,12 @@ mod tests {
assert!(result.is_ok());

// check
let expected_files = get_files_in_folder_recursive(&data_path);
let expected = expected_files
let binding = get_files_in_folder_recursive(&data_path);
let mut expected_files = binding
.iter()
.filter(|f| !f.ends_with(".DS_Store"))
.collect::<Vec<_>>();
let mut expected = expected_files
.iter()
.map(|f| {
// Convert the absolute path to a relative path
Expand All @@ -83,10 +97,15 @@ mod tests {
}
})
.map(|f| f.to_string_lossy().to_ascii_lowercase())
.map(|f| f.replace('\\', "/"))
.collect::<Vec<_>>();

let found_files = get_files_in_folder_recursive(&dst_path);
let found = found_files
let binding = get_files_in_folder_recursive(&dst_path);
let mut found_files = binding
.iter()
.filter(|f| !f.ends_with(".DS_Store"))
.collect::<Vec<_>>();
let mut found = found_files
.iter()
.map(|f| {
// Convert the absolute path to a relative path
Expand All @@ -97,14 +116,20 @@ mod tests {
}
})
.map(|f| f.to_string_lossy().to_ascii_lowercase())
.map(|f| f.replace('\\', "/"))
.collect::<Vec<_>>();

expected.sort();
found.sort();
expected_files.sort();
found_files.sort();

assert_eq!(expected.len(), found.len());
assert_eq!(expected, found);

for (i, e) in expected_files.into_iter().enumerate() {
let f = found_files.get(i).unwrap();
assert_binary_equality(&e, f);
assert_binary_equality(e, f);
}

// cleanup
Expand Down
Binary file added tests/srxl.bin
Binary file not shown.

0 comments on commit 9a41866

Please sign in to comment.