/// Download the glibc deb package with a given name, find a file inside it, and
/// extract the file.
Download the glibc deb package with a given name, find a file inside it, and
extract the file.
Download the glibc deb package with a given name find a file inside it and extract the file .
pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
    deb_file_name: &str,
    file_name: &str,
    out_path: P,
) -> Result<()> {
    let out_path = out_path.as_ref();
    let deb_bytes = request_ubuntu_pkg(deb_file_name)?;
    let mut deb = ar::Archive::new(deb_bytes);
    // Try to find data.tar in package
    while let Some(Ok(entry)) = deb.next_entry() {
        let path = entry.header().identifier();
        let path = Path::new(OsStr::from_bytes(path));
        let stem = path.file_stem().map(OsStr::as_bytes);
        if stem != Some(b"data.tar") {
            continue;
        }
        // Detect extension and decompress
        let ext = path
            .extension()
            .map(OsStr::as_bytes)
            .context(DataNotFoundSnafu)?;
        match ext {
            b"gz" => {
                let data = GzDecoder::new(entry);
                write_ubuntu_data_tar_file(data, file_name, out_path)
            }
            b"xz" => {
                let data = LzmaReader::new_decompressor(entry).context(DataUnzipSnafu)?;
                write_ubuntu_data_tar_file(data, file_name, out_path)
            }
            ext => None.context(DataExtSnafu { ext }),
        }?;
        return Ok(());
    }
    Err(Error::DataNotFound)
}
pub fn write_ubuntu_pkg_file < P : AsRef < Path > > ( deb_file_name : & str , file_name : & str , out_path : P , ) -> Result < ( ) > { let out_path = out_path . as_ref ( ) ; let deb_bytes = request_ubuntu_pkg ( deb_file_name ) ? ; let mut deb = ar :: Archive :: new ( deb_bytes ) ; // Try to find data.tar in package while let Some ( Ok ( entry ) ) = deb . next_entry ( ) { let path = entry . header ( ) . identifier ( ) ; let path = Path :: new ( OsStr :: from_bytes ( path ) ) ; let stem = path . file_stem ( ) . map ( OsStr :: as_bytes ) ; if stem != Some ( b" " ) { continue ; } // Detect extension and decompress let ext = path . extension ( ) . map ( OsStr :: as_bytes ) . context ( DataNotFoundSnafu ) ? ; match ext { b" " => { let data = GzDecoder :: new ( entry ) ; write_ubuntu_data_tar_file ( data , file_name , out_path ) } b" " => { let data = LzmaReader :: new_decompressor ( entry ) . context ( DataUnzipSnafu ) ? ; write_ubuntu_data_tar_file ( data , file_name , out_path ) } ext => None . context ( DataExtSnafu { ext } ) , } ? ; return Ok ( ( ) ) ; } Err ( Error :: DataNotFound ) }
Download the glibc deb package with a given name, find a file inside it, and
extract the file.
Download the glibc deb package with a given name find a file inside it and extract the file .
deb_file_name
&str
file_name
&str
out_path
P