1use std::{
12 fs,
13 io,
14 io::Seek,
15 path::Path,
16};
17use tar;
18#[allow(unused_imports)]
19use tracing::{
20 debug,
21 error,
22 info,
23 warn,
24};
25
26pub fn targz(outdir: impl AsRef<Path>, srcpath: impl AsRef<Path>) -> io::Result<()>
28{
29 use flate2::bufread::GzDecoder;
30 let mut src = io::BufReader::new(fs::File::open(srcpath.as_ref())?);
31 src.seek(io::SeekFrom::Start(0))?;
32 let enc = GzDecoder::new(src);
33 let mut ar = tar::Archive::new(enc);
34 ar.unpack(outdir.as_ref())?;
35 debug!(
36 "Successfully decompressed and extracted tape gz-compressed archive from {} to {}",
37 srcpath.as_ref().to_string_lossy(),
38 outdir.as_ref().to_string_lossy(),
39 );
40 Ok(())
41}
42
43pub fn tarzst(outdir: impl AsRef<Path>, srcpath: impl AsRef<Path>) -> io::Result<()>
45{
46 use zstd::Decoder;
47 let mut src = io::BufReader::new(fs::File::open(srcpath.as_ref())?);
48 src.seek(io::SeekFrom::Start(0))?;
49 let enc = Decoder::new(src)?;
50 let mut ar = tar::Archive::new(enc);
51 ar.unpack(outdir.as_ref())?;
52 debug!(
53 "Successfully decompressed and extracted tape zstd-compressed archive from {} to {}",
54 srcpath.as_ref().to_string_lossy(),
55 outdir.as_ref().to_string_lossy(),
56 );
57 Ok(())
58}
59
60pub fn tarxz(outdir: impl AsRef<Path>, srcpath: impl AsRef<Path>) -> io::Result<()>
62{
63 use xz2::read::XzDecoder;
64 let mut src = io::BufReader::new(fs::File::open(srcpath.as_ref())?);
65 src.seek(io::SeekFrom::Start(0))?;
66 let enc = XzDecoder::new(src);
67 let mut ar = tar::Archive::new(enc);
68 ar.unpack(outdir.as_ref())?;
69 debug!(
70 "Successfully decompressed and extracted tape xz-compressed archive from {} to {}",
71 srcpath.as_ref().to_string_lossy(),
72 outdir.as_ref().to_string_lossy(),
73 );
74 Ok(())
75}
76
77pub fn tarbz2(outdir: impl AsRef<Path>, srcpath: impl AsRef<Path>) -> io::Result<()>
79{
80 use bzip2::bufread::MultiBzDecoder;
81
82 let mut src = io::BufReader::new(fs::File::open(srcpath.as_ref())?);
83 src.seek(io::SeekFrom::Start(0))?;
84 let enc = MultiBzDecoder::new(src);
85 let mut ar = tar::Archive::new(enc);
86 ar.unpack(outdir.as_ref())?;
87 debug!(
88 "Successfully decompressed and extracted tape bz2-compressed archive from {} to {}",
89 srcpath.as_ref().to_string_lossy(),
90 outdir.as_ref().to_string_lossy(),
91 );
92 Ok(())
93}
94
95pub fn vanilla(outdir: impl AsRef<Path>, srcpath: impl AsRef<Path>) -> io::Result<()>
97{
98 let mut src = io::BufReader::new(fs::File::open(srcpath.as_ref())?);
99 src.seek(io::SeekFrom::Start(0))?;
100 let mut ar = tar::Archive::new(src);
101 ar.unpack(outdir.as_ref())?;
102 debug!(
103 "Successfully extracted tape archive from {} to {}",
104 srcpath.as_ref().to_string_lossy(),
105 outdir.as_ref().to_string_lossy(),
106 );
107 Ok(())
108}