diff --git a/Cargo.toml b/Cargo.toml index 0eb941e5..65189d8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ edition = "2018" [workspace] members = ["systest"] + [dependencies] lzma-sys = { path = "lzma-sys", version = "0.1.11" } tokio-io = { version = "0.1.12", optional = true } @@ -26,6 +27,7 @@ futures = { version = "0.1.26", optional = true } [dev-dependencies] rand = "0.7.0" quickcheck = "0.9.0" +tar = "0.4.26" tokio-core = "0.1.17" [features] diff --git a/examples/unpack-archive.rs b/examples/unpack-archive.rs new file mode 100644 index 00000000..81f053c4 --- /dev/null +++ b/examples/unpack-archive.rs @@ -0,0 +1,19 @@ +use std::{fs, io::Read, path::PathBuf}; +use tar::Archive; +use xz2::read::XzDecoder; + +fn unpack_tar_xz(archive_path: &PathBuf, dest: &PathBuf) { + let archive_bytes = fs::read(archive_path).expect("Problem reading archive as bytes"); + + let mut tar: Vec = Vec::new(); + let mut decompressor = XzDecoder::new(&archive_bytes[..]); + decompressor.read_to_end(&mut tar).expect("Problem decompressing archive"); + + // We've decompressed the .xz; now unpack the tar. + let mut archive = Archive::new(&tar[..]); + archive.unpack(dest).expect("Problem unpacking tar"); +} + +fn main() { + +} \ No newline at end of file