/// Transform the ZIP provided by cortex into a TempDir,
/// for e.g. tools such as Engrafo that aren't ZIP-capable
Transform the ZIP provided by cortex into a TempDir,
for e.g. tools such as Engrafo that aren't ZIP-capable
Transform the ZIP provided by cortex into a TempDir for e . g . tools such as Engrafo that aren ' t ZIP - capable
pub fn extract_zip_to_tmpdir(path: &Path, tmpdir_prefix: &str) -> Result<TempDir, Box<dyn Error>> {
    let input_tmpdir = TempDir::new(tmpdir_prefix)?;
    let unpacked_dir_path = input_tmpdir.path().to_str().unwrap().to_string() + "/";
    // unpack the Zip file for engrafo
    let inputzip = File::open(&path)?;
    let mut input_archive = ZipArchive::new(inputzip)?;
    for i in 0..input_archive.len() {
        let mut file = input_archive.by_index(i)?;
        let extract_path = file.mangled_name();
        let extract_pathname = extract_path.as_path().display();
        let full_pathname = format!("{}{}", unpacked_dir_path, extract_pathname);
        if (&*file.name()).ends_with('/') {
            create_dir_all(&full_pathname)?;
        } else {
            if let Some(p) = extract_path.parent() {
                if !p.exists() {
                    let absolute_parent = format!("{}{}", unpacked_dir_path, p.display());
                    create_dir_all(&absolute_parent)?;
                }
            }
            let mut extracted_file = File::create(&full_pathname)?;
            copy(&mut file, &mut extracted_file)?;
        }
    }
    Ok(input_tmpdir)
}
pub fn extract_zip_to_tmpdir ( path : & Path , tmpdir_prefix : & str ) -> Result < TempDir , Box < dyn Error > > { let input_tmpdir = TempDir :: new ( tmpdir_prefix ) ? ; let unpacked_dir_path = input_tmpdir . path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) + " " ; // unpack the Zip file for engrafo let inputzip = File :: open ( & path ) ? ; let mut input_archive = ZipArchive :: new ( inputzip ) ? ; for i in 0 .. input_archive . len ( ) { let mut file = input_archive . by_index ( i ) ? ; let extract_path = file . mangled_name ( ) ; let extract_pathname = extract_path . as_path ( ) . display ( ) ; let full_pathname = format ! ( " " unpacked_dir_path extract_pathname ) ; if ( & * file . name ( ) ) . ends_with ( '/' ) { create_dir_all ( & full_pathname ) ? ; } else { if let Some ( p ) = extract_path . parent ( ) { if ! p . exists ( ) { let absolute_parent = format ! ( " " unpacked_dir_path p display ( ) ) ; create_dir_all ( & absolute_parent ) ? ; } } let mut extracted_file = File :: create ( & full_pathname ) ? ; copy ( & mut file , & mut extracted_file ) ? ; } } Ok ( input_tmpdir ) }
Transform the ZIP provided by cortex into a TempDir,
for e.g.
Transform the ZIP provided by cortex into a TempDir for e . g .
path
&Path
tmpdir_prefix
&str