/// Extract the archive to a folder and return the path to the extracted files. Zip/tar/tar.gz archives are supported.
/// If extraction target path isn't provided and the function is executed from a build script, the build script output folder is used.
/// 
/// ```
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let path_to_lib_zip = std::path::Path::new("./whatever.zip");
/// let path_to_dylib_folder = librarian::extract_archive(path_to_lib_zip, None)?.join("bin");
/// librarian::install_dylibs(&path_to_dylib_folder, None, None)?;
/// # Ok(())
/// # }
/// ```
Extract the archive to a folder and return the path to the extracted files.


Extract the archive to a folder and return the path to the extracted files .
pub fn extract_archive<T: AsRef<Path> + ?Sized>(
    archive: &T,
    target: Option<&Path>
) -> Result<PathBuf, ExtractError> {
    let target = if let Some(target) = target {
        PathBuf::from(target)
    } else {
        PathBuf::from(env::var("OUT_DIR").expect("You must provide the output directory when not running from a build script."))
    };
    let fn_as_str = archive.as_ref().file_name().unwrap().to_string_lossy();
    #[cfg(feature = "zip")]
    {
        if fn_as_str.ends_with(".zip") {
            crate::zip::extract_zip(archive, target.as_path())?;
            return Ok(target);
        }
    }
    #[cfg(feature = "tgz")]
    {
        if fn_as_str.ends_with(".tar.gz") || fn_as_str.ends_with(".tgz") {
            crate::tgz::extract_tar_gz(archive, target.as_path())?;
            return Ok(target);
        }
    }
    #[cfg(feature = "tar")]
    {
        if fn_as_str.ends_with(".tar") {
            crate::tgz::extract_tar(archive, target.as_path())?;
            return Ok(target);
        }
    }
    panic!("archive format not supported");
}
pub fn extract_archive < T : AsRef < Path > + ? Sized > ( archive : & T , target : Option < & Path > ) -> Result < PathBuf , ExtractError > { let target = if let Some ( target ) = target { PathBuf :: from ( target ) } else { PathBuf :: from ( env :: var ( " " ) . expect ( " " ) ) } ; let fn_as_str = archive . as_ref ( ) . file_name ( ) . unwrap ( ) . to_string_lossy ( ) ; # [ cfg ( feature " " ) ] { if fn_as_str . ends_with ( " " ) { crate :: zip :: extract_zip ( archive , target . as_path ( ) ) ? ; return Ok ( target ) ; } } # [ cfg ( feature " " ) ] { if fn_as_str . ends_with ( " " ) || fn_as_str . ends_with ( " " ) { crate :: tgz :: extract_tar_gz ( archive , target . as_path ( ) ) ? ; return Ok ( target ) ; } } # [ cfg ( feature " " ) ] { if fn_as_str . ends_with ( " " ) { crate :: tgz :: extract_tar ( archive , target . as_path ( ) ) ? ; return Ok ( target ) ; } } panic ! ( " " ) ; }
Extract the archive to a folder and return the path to the extracted files.
Extract the archive to a folder and return the path to the extracted files .
archive
&T
target
Option<&Path>
fn run() -> result<(), box<dyn std::error::error>> {
None
let path_to_lib_zip = std::path::path::new("./whatever.zip");
None
ok(())
None
}
None