Skip to main content

oceanpkg/
archive.rs

1//! Archiving utilities.
2
3use std::{
4    io,
5    path::Path,
6};
7use flate2::read::GzDecoder;
8
9/// Reads `tarball` as a `.tar.gz` file and unpacks it to `path`.
10///
11/// Because `GzDecoder` uses a buffered reader internally, this is appropriate
12/// to call on `File`s.
13pub fn unpack_tarball<R, P>(tarball: R, path: P) -> io::Result<()>
14where
15    R: io::Read,
16    P: AsRef<Path>,
17{
18    let decoder = GzDecoder::new(tarball);
19    println!("{:#?}", decoder.header());
20    tar::Archive::new(decoder).unpack(path)
21}