diff --git a/rust/src/main.rs b/rust/src/main.rs index 9343e22..9293bc0 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -59,7 +59,19 @@ fn main() -> Result<(), Box> { fn producer(input: &Path, chunkk: Vec, ttx: Sender<(String, Vec, bool)>) { let params = file_compress_params(); for path in chunkk { - compress_file(&path, input, ¶ms, &ttx); + let tx = &ttx; + let path_strip = strip_input(&path, input); + let path_str = path_strip.to_string_lossy(); + if compressable(&path) { + let mut content_compressed = Vec::new(); + let mut file = File::open(&path).unwrap(); + brotli::BrotliCompress(&mut file, &mut content_compressed, ¶ms).unwrap(); + tx.send((path_str.to_string(), content_compressed, true)) + .unwrap(); + } else { + let content = read(path.clone()).unwrap(); + tx.send((path_str.to_string(), content, false)).unwrap(); + } } } @@ -88,21 +100,6 @@ fn make_conn(output: &str) -> Result> { type Entry = (String, Vec, bool); -fn compress_file(path: &Path, input: &Path, params: &BrotliEncoderParams, tx: &Sender) { - let path_strip = strip_input(&path, input); - let path_str = path_strip.to_string_lossy(); - if compressable(path) { - let mut content_compressed = Vec::new(); - let mut file = File::open(path).unwrap(); - brotli::BrotliCompress(&mut file, &mut content_compressed, ¶ms).unwrap(); - tx.send((path_str.to_string(), content_compressed, true)) - .unwrap(); - } else { - let content = read(path.clone()).unwrap(); - tx.send((path_str.to_string(), content, false)).unwrap(); - } -} - fn make_db_schema(conn: &Connection) -> Result<(), Box> { conn.execute( "create table files(path text, content blob, compressed bool)",