MeiliSearch/meilisearch-lib/src/compression.rs

27 lines
762 B
Rust
Raw Normal View History

2021-09-28 11:59:55 +02:00
use std::fs::File;
2021-03-22 19:19:37 +01:00
use std::io::Write;
2020-12-12 13:32:06 +01:00
use std::path::Path;
2021-03-22 19:19:37 +01:00
2021-09-28 11:59:55 +02:00
use flate2::{write::GzEncoder, Compression};
use tar::Builder;
2020-12-12 13:32:06 +01:00
2021-03-23 16:37:46 +01:00
pub fn to_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
2021-03-22 19:19:37 +01:00
let mut f = File::create(dest)?;
let gz_encoder = GzEncoder::new(&mut f, Compression::default());
2020-12-12 13:32:06 +01:00
let mut tar_encoder = Builder::new(gz_encoder);
tar_encoder.append_dir_all(".", src)?;
let gz_encoder = tar_encoder.into_inner()?;
gz_encoder.finish()?;
2021-03-22 19:19:37 +01:00
f.flush()?;
2020-12-12 13:32:06 +01:00
Ok(())
}
2021-09-27 16:48:03 +02:00
//pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
2021-09-28 22:22:59 +02:00
//let f = File::open(&src)?;
//let gz = GzDecoder::new(f);
//let mut ar = Archive::new(gz);
//create_dir_all(&dest)?;
//ar.unpack(&dest)?;
//Ok(())
2021-09-27 16:48:03 +02:00
//}