From 92a9ab834006ad5610609da379ff5a20890ab9e3 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sun, 23 Apr 2023 21:13:20 -0300 Subject: [PATCH] rust: clean --- rust/src/main.rs | 93 ------------------------------------------------ 1 file changed, 93 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index 11ee5ef..5932d64 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -20,9 +20,6 @@ fn main() -> Result<(), Box> { make_db_schema(&conn)?; let input = Path::new("./input"); - // let (dict, dict_id) = make_dict(conn, input)?; - - // let mut enc = zstd::bulk::Compressor::new(5)?; let paths = iterator(input).collect::>(); let chunks = paths.chunks(paths.len() / 4); @@ -37,13 +34,6 @@ fn main() -> Result<(), Box> { thread::spawn(move || { let input = Path::new("./input"); let params = file_compress_params(); - // let mut conn = make_conn().unwrap(); - println!("thread"); - // let trans = conn.transaction().unwrap(); - // { - // let mut insert_stmt = trans - // .prepare_cached("insert into files(path, content, compressed) values(?, ?, ?)") - // .unwrap(); for path in chunkk { compress_file(&path, input, ¶ms, &ttx); } @@ -70,67 +60,9 @@ fn main() -> Result<(), Box> { for thread in threads { thread.join().unwrap(); } - // .map(|path| -> Option<()> { - // insert_file(path, input, params, insert_stmt); - // Some(()) - // }) - // .collect::>>(); - // if iter.iter().any(|o| o.is_none()) { - // println!("Algo falló"); - // } - - // recurse(dict, conn)?; - - println!("Hello, world!"); Ok(()) } -// fn insert_files(paths: &[PathBuf]) { -// let input = Path::new("./input"); -// let params = file_compress_params(); -// // let mut conn = make_conn().unwrap(); -// println!("thread"); -// // let trans = conn.transaction().unwrap(); -// // { -// // let mut insert_stmt = trans -// // .prepare_cached("insert into files(path, content, compressed) values(?, ?, ?)") -// // .unwrap(); -// for path in paths { -// compress_file(path, input, ¶ms, tx); -// } -// // insert_stmt.execute((path_str, content, false)).unwrap(); -// // } -// // trans.commit().unwrap(); -// } - -// fn insert_file( -// path: &Path, -// input: &Path, -// params: &BrotliEncoderParams, -// insert_stmt: &mut rusqlite::CachedStatement, -// ) { -// // let mut path_comp = zstd::bulk::Compressor::with_dictionary(0, &dict).unwrap(); - -// // println!("{:?}", path); -// // let path_compressed = path_comp -// // .compress(strip_input(&path, input).to_string_lossy().as_bytes()) -// // .unwrap(); -// 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(); -// // let content_compressed = enc.compress(&content)?; -// insert_stmt -// .execute((path_str, content_compressed, true)) -// .unwrap(); -// } else { -// let content = read(path.clone()).unwrap(); -// insert_stmt.execute((path_str, content, false)).unwrap(); -// } -// } - fn make_conn() -> Result> { let conn = Connection::open(db_path())?; conn.pragma_update(None, "journal_mode", "OFF")?; @@ -147,15 +79,10 @@ fn compress_file(path: &Path, input: &Path, params: &BrotliEncoderParams, tx: &S let mut content_compressed = Vec::new(); let mut file = File::open(path).unwrap(); brotli::BrotliCompress(&mut file, &mut content_compressed, ¶ms).unwrap(); - // let content_compressed = enc.compress(&content)?; - // insert_stmt - // .execute((path_str, content_compressed, true)) - // .unwrap(); tx.send((path_str.to_string(), content_compressed, true)) .unwrap(); } else { let content = read(path.clone()).unwrap(); - // insert_stmt.execute((path_str, content, false)).unwrap(); tx.send((path_str.to_string(), content, false)).unwrap(); } } @@ -165,30 +92,10 @@ fn make_db_schema(conn: &Connection) -> Result<(), Box> { "create table files(path text, content blob, compressed bool)", [], )?; - // conn.execute( - // "create table files(path blob, path_dictionary_id integer, content blob, compressed bool)", - // [], - // )?; - // conn.execute("create table path_dictionaries(dictionary blob)", [])?; conn.execute("create unique index path on files(path)", [])?; Ok(()) } -// fn make_dict(conn: Connection, input: &Path) -> Result<(Vec, i64), Box> { -// let mut insert_dict_stmt = -// conn.prepare_cached("insert into path_dictionaries(dictionary) values(?1)")?; -// let mut all_paths = Vec::new(); -// let iter = iterator(input); -// for entry in iter { -// all_paths.push(entry.to_string_lossy().as_bytes().to_vec()); -// } -// println!("path n {}", all_paths.len()); -// let dict = zstd::dict::from_samples(&all_paths, 999999)?; -// println!("dict"); -// let dict_id = insert_dict_stmt.insert(params![&dict])?; -// Ok((dict, dict_id)) -// } - fn file_compress_params() -> BrotliEncoderParams { let mut params = BrotliEncoderParams::default(); params.quality = 0;