pub fn uncompress_archive_file<R, W>(source: R, target: W, path: &str) -> Result<usize>
where
    R: Read + Seek,
    W: Write,
{
    let _utf8_guard = ffi::UTF8LocaleGuard::new();
    run_with_archive(
        Ownership::Ignore,
        source,
        |archive_reader, _, mut entry| unsafe {
            loop {
                match ffi::archive_read_next_header(archive_reader, &mut entry) {
                    ffi::ARCHIVE_OK => {
                        let file_name = CStr::from_ptr(ffi::archive_entry_pathname(entry))
                            .to_string_lossy()
                            .into_owned();
                        if file_name == path {
                            break;
                        }
                    }
                    ffi::ARCHIVE_EOF => {
                        return Err(io::Error::new(
                            io::ErrorKind::NotFound,
                            format!("path {} doesn't exist inside archive", path),
                        )
                        .into())
                    }
                    _ => return Err(Error::from(archive_reader)),
                }
            }
            libarchive_write_data_block(archive_reader, target)
        },
    )
}
/// Uncompress a specific file from an archive. The `source` is used as a
/// reader, the `target` as a writer and the `path` is the relative path for
/// the file to be extracted from the archive.
///
/// # Example
///
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use compress_tools::*;
/// use std::fs::File;
///
/// let mut source = File::open("tree.tar.gz")?;
/// let mut target = Vec::default();
///
/// uncompress_archive_file(&mut source, &mut target, "file/path")?;
/// # Ok(())
/// # }
/// ```
Uncompress a specific file from an archive.
Uncompress a specific file from an archive .
pub fn uncompress_archive_file<R, W>(source: R, target: W, path: &str) -> Result<usize>
where
    R: Read + Seek,
    W: Write,
{
    let _utf8_guard = ffi::UTF8LocaleGuard::new();
    run_with_archive(
        Ownership::Ignore,
        source,
        |archive_reader, _, mut entry| unsafe {
            loop {
                match ffi::archive_read_next_header(archive_reader, &mut entry) {
                    ffi::ARCHIVE_OK => {
                        let file_name = CStr::from_ptr(ffi::archive_entry_pathname(entry))
                            .to_string_lossy()
                            .into_owned();
                        if file_name == path {
                            break;
                        }
                    }
                    ffi::ARCHIVE_EOF => {
                        return Err(io::Error::new(
                            io::ErrorKind::NotFound,
                            format!("path {} doesn't exist inside archive", path),
                        )
                        .into())
                    }
                    _ => return Err(Error::from(archive_reader)),
                }
            }
            libarchive_write_data_block(archive_reader, target)
        },
    )
}
pub fn uncompress_archive_file < R , W > ( source : R , target : W , path : & str ) -> Result < usize > where R : Read + Seek , W : Write , { let _utf8_guard = ffi :: UTF8LocaleGuard :: new ( ) ; run_with_archive ( Ownership :: Ignore , source , | archive_reader , _ , mut entry | unsafe { loop { match ffi :: archive_read_next_header ( archive_reader , & mut entry ) { ffi :: ARCHIVE_OK => { let file_name = CStr :: from_ptr ( ffi :: archive_entry_pathname ( entry ) ) . to_string_lossy ( ) . into_owned ( ) ; if file_name == path { break ; } } ffi :: ARCHIVE_EOF => { return Err ( io :: Error :: new ( io :: ErrorKind :: NotFound , format ! ( " " path ) , ) . into ( ) ) } _ => return Err ( Error :: from ( archive_reader ) ) , } } libarchive_write_data_block ( archive_reader , target ) } , ) }
Uncompress a specific file from an archive.
Uncompress a specific file from an archive .
source
R
target
W
path
&str
source
R
target
W
path
&str
example
None
fn main() -> result<(), box<dyn std::error::error>> {
use compress_tools::*;
use std::fs::File.

let mut source = File::open("tree.tar.gz")?;
let mut target = Vec::default().

uncompress_archive_file(&mut source, &mut target, "file/path")?.
use compress_tools :: * ; use std :: fs :: File . let mut source = File :: open ( " tree . tar . gz " ) ? ; let mut target = Vec :: default () . uncompress_archive_file ( &mut source &mut target " file / path " ) ? .
ok(())
None
}
None