Support LZ4 compression
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
[package]
|
||||
name = "tool_helper"
|
||||
version = "0.5.0"
|
||||
version = "0.6.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cdtypes = {path = "../cdtypes"}
|
||||
lz4 = "*"
|
||||
paste = "*"
|
14
src/Tools/tool_helper/src/compress.rs
Normal file
14
src/Tools/tool_helper/src/compress.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
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())?;
|
||||
|
||||
std::io::copy(&mut&data[..], &mut lz4_encoder)?;
|
||||
let (output, result) = lz4_encoder.finish();
|
||||
|
||||
match result {
|
||||
Ok(()) => Ok(output),
|
||||
Err(error) => Err(Error::from_error(error))
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
|
||||
|
||||
pub mod bits;
|
||||
pub mod compress;
|
||||
pub mod raw;
|
||||
|
||||
pub type BufferedInputFile = BufReader<std::fs::File>;
|
||||
|
Reference in New Issue
Block a user