rust: mover código
This commit is contained in:
parent
3d3ac7c655
commit
bade1e4913
1 changed files with 13 additions and 16 deletions
|
@ -59,7 +59,19 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
fn producer(input: &Path, chunkk: Vec<PathBuf>, ttx: Sender<(String, Vec<u8>, 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<Connection, Box<dyn Error>> {
|
|||
|
||||
type Entry = (String, Vec<u8>, bool);
|
||||
|
||||
fn compress_file(path: &Path, input: &Path, params: &BrotliEncoderParams, tx: &Sender<Entry>) {
|
||||
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<dyn Error>> {
|
||||
conn.execute(
|
||||
"create table files(path text, content blob, compressed bool)",
|
||||
|
|
Loading…
Reference in a new issue