Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs::File;
- use std::io::{Error, Read};
- use std::path::Path;
- pub fn untar(tar_file: &Path, destination_dir: &Path, is_tar_gz: bool) -> Result<(), Error> {
- let file = File::open(tar_file)?;
- let archive = if is_tar_gz {
- let decoder = flate2::read::GzDecoder::new(file);
- tar::Archive::new(decoder)
- } else {
- tar::Archive::new(file)
- };
- unpack(archive, &destination_dir)
- }
- fn unpack<R: Read>(mut archive: tar::Archive<R>, destination_dir: &Path) -> Result<(), Error> {
- archive.set_preserve_permissions(true);
- archive.set_preserve_mtime(true);
- Ok(archive.unpack(&destination_dir)?)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement