Broken LZ4 algorithm! The decompression seems to work now (needs improvement?) but the conversion tools emit 64K block sizes which is unhelpfull for us

This commit is contained in:
2022-12-29 23:18:37 +01:00
parent 3554394e11
commit 3d56532a3b
7 changed files with 250 additions and 15 deletions

View File

@@ -21,13 +21,14 @@ struct CommandLine {
#[derive(Subcommand)]
enum SubCommands {
Nothing,
SimpleTIM(reduced_tim::Arguments)
}
fn run_main() -> Result<(), Error> {
match CommandLine::try_parse() {
Ok(cmd) => {
let input = tool_helper::open_input(cmd.input_file)?;
let mut input = tool_helper::open_input(cmd.input_file)?;
let mut buffer = Vec::<u8>::new();
let mut output_file = tool_helper::open_output(cmd.output_file)?;
let dst_buffer = {
@@ -41,6 +42,9 @@ fn run_main() -> Result<(), Error> {
};
match cmd.sub_command {
SubCommands::Nothing => {
std::io::copy(&mut input, dst_buffer)?;
},
SubCommands::SimpleTIM(args) => {
reduced_tim::convert(args, input, dst_buffer)?;
}
@@ -48,10 +52,7 @@ fn run_main() -> Result<(), Error> {
// We encoded the file to a temporary buffer and now need to write it
if cmd.compress_lz4 {
println!("Buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
let buffer = tool_helper::compress::lz4(&buffer, 16)?;
println!("New buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
output_file.write(&buffer)?;
}

View File

@@ -2,7 +2,7 @@ use super::Error;
use lz4::EncoderBuilder;
pub fn lz4(data: &Vec<u8>, compression_level: u32) -> Result<Vec<u8>, Error> {
let mut lz4_encoder = EncoderBuilder::new().level(compression_level).build(Vec::<u8>::new())?;
let mut lz4_encoder = EncoderBuilder::new().level(compression_level).checksum(lz4::ContentChecksum::NoChecksum).build(Vec::<u8>::new())?;
std::io::copy(&mut&data[..], &mut lz4_encoder)?;
let (output, result) = lz4_encoder.finish();