Closed Mozartuss closed 3 years ago
If someone is looking for the solution here it is:
the function compress all files in a given folder path and return a Vec<u8>
fn compress(input_path: &PathBuf) -> anyhow::Result<Vec<u8>, io::Error> {
let encoder = GzEncoder::new(Vec::new(), Compression::fast());
let mut tar = tar::Builder::new(encoder);
tar.append_dir_all(".", &input_path)?;
let encoder_data: GzEncoder<Vec<u8>> = tar.into_inner()?;
let compress_vec: Vec<u8> = encoder_data.finish()?;
Ok(compress_vec)
}
Is it possible to build a tar-file recursively from a Folder without to save it. I currently use the
Builder
with.append_dir_all()
. In my use case I only need the byte vector of the tar-file to work with this.