Support LZ4 compression
This commit is contained in:
@@ -117,7 +117,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
||||
let mut desc_file = {
|
||||
match file.kind {
|
||||
config_reader::FileKind::Regular => types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?,
|
||||
config_reader::FileKind::Overlay => types::overlay::load_from(file.path)?,
|
||||
config_reader::FileKind::Overlay => types::overlay::load_from(file.common.name.as_str(), file.path)?,
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
use super::File;
|
||||
use std::path::PathBuf;
|
||||
use byteorder::{ByteOrder, BigEndian, LittleEndian};
|
||||
use lz4::EncoderBuilder;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use tool_helper::{Error, format_if_error, read_file};
|
||||
|
||||
#[repr(packed)]
|
||||
@@ -17,7 +16,7 @@ impl OverlayHeader {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_from(file_path: PathBuf) -> Result<File, Error> {
|
||||
pub fn load_from(file_name: &str, file_path: PathBuf) -> Result<File, Error> {
|
||||
let overlay_header_size = std::mem::size_of::<OverlayHeader>();
|
||||
let mut content = read_file(&file_path)?;
|
||||
|
||||
@@ -39,17 +38,6 @@ pub fn load_from(file_path: PathBuf) -> Result<File, Error> {
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let mut lz4_encoder = EncoderBuilder::new().level(16).build(Vec::<u8>::new())?;
|
||||
|
||||
std::io::copy(&mut&content[..], &mut lz4_encoder)?;
|
||||
let (output, result) = lz4_encoder.finish();
|
||||
|
||||
match result {
|
||||
Ok(()) => println!("Wuff: {}", output.len()),
|
||||
Err(error) => {
|
||||
return Err(Error::from_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
Err(Error::not_implemented("load_from overlay"))
|
||||
let content = format_if_error!(tool_helper::compress::lz4(content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?;
|
||||
Ok(File::new_overlay(file_name, content)?)
|
||||
}
|
Reference in New Issue
Block a user