1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
//! Archiving utilities.

use std::{
    io,
    path::Path,
};
use flate2::read::GzDecoder;

/// Reads `tarball` as a `.tar.gz` file and unpacks it to `path`.
///
/// Because `GzDecoder` uses a buffered reader internally, this is appropriate
/// to call on `File`s.
pub fn unpack_tarball<R, P>(tarball: R, path: P) -> io::Result<()>
where
    R: io::Read,
    P: AsRef<Path>,
{
    let decoder = GzDecoder::new(tarball);
    println!("{:#?}", decoder.header());
    tar::Archive::new(decoder).unpack(path)
}