/// Extracts extensions from a path,
/// return both the remaining path and the list of extension objects
Extracts extensions from a path,
return both the remaining path and the list of extension objects
Extracts extensions from a path return both the remaining path and the list of extension objects
pub fn separate_known_extensions_from_name(mut path: &Path) -> (&Path, Vec<Extension>) {
    let original_path = path.to_owned();
    // // TODO: check for file names with the name of an extension
    // // TODO2: warn the user that currently .tar.gz is a .gz file named .tar
    //
    // let all = ["tar", "zip", "bz", "bz2", "gz", "xz", "lzma", "lz"];
    // if path.file_name().is_some() && all.iter().any(|ext| path.file_name().unwrap() == *ext) {
    //     todo!("we found a extension in the path name instead, what to do with this???");
    // }
    let mut extensions = vec![];
    // While there is known extensions at the tail, grab them
    while let Some(extension) = path.extension().and_then(OsStr::to_str) {
        extensions.push(match extension {
            "tar" => Extension::new([Tar], extension),
            "tgz" => Extension::new([Tar, Gzip], extension),
            "tbz" | "tbz2" => Extension::new([Tar, Bzip], extension),
            "txz" | "tlz" | "tlzma" => Extension::new([Tar, Lzma], extension),
            "tzst" => Extension::new([Tar, Zstd], ".tzst"),
            "zip" => Extension::new([Zip], extension),
            "bz" | "bz2" => Extension::new([Bzip], extension),
            "gz" => Extension::new([Gzip], extension),
            "xz" | "lzma" | "lz" => Extension::new([Lzma], extension),
            "zst" => Extension::new([Zstd], extension),
            _ => break,
        });
        // Update for the next iteration
        path = if let Some(stem) = path.file_stem() { Path::new(stem) } else { Path::new("") };
    }
    // Put the extensions in the correct order: left to right
    extensions.reverse();
    if extensions.is_empty() {
        try_infer(original_path, &mut extensions);
    }
    (path, extensions)
}
pub fn separate_known_extensions_from_name ( mut path : & Path ) -> ( & Path , Vec < Extension > ) { let original_path = path . to_owned ( ) ; // // TODO: check for file names with the name of an extension // // TODO2: warn the user that currently .tar.gz is a .gz file named .tar // // let all = ["tar", "zip", "bz", "bz2", "gz", "xz", "lzma", "lz"]; // if path.file_name().is_some() && all.iter().any(|ext| path.file_name().unwrap() == *ext) { //     todo!("we found a extension in the path name instead, what to do with this???"); // } let mut extensions = vec ! [ ] ; // While there is known extensions at the tail, grab them while let Some ( extension ) = path . extension ( ) . and_then ( OsStr :: to_str ) { extensions . push ( match extension { " " => Extension :: new ( [ Tar ] , extension ) , " " => Extension :: new ( [ Tar , Gzip ] , extension ) , " " | " " => Extension :: new ( [ Tar , Bzip ] , extension ) , " " | " " | " " => Extension :: new ( [ Tar , Lzma ] , extension ) , " " => Extension :: new ( [ Tar , Zstd ] , " " ) , " " => Extension :: new ( [ Zip ] , extension ) , " " | " " => Extension :: new ( [ Bzip ] , extension ) , " " => Extension :: new ( [ Gzip ] , extension ) , " " | " " | " " => Extension :: new ( [ Lzma ] , extension ) , " " => Extension :: new ( [ Zstd ] , extension ) , _ => break , } ) ; // Update for the next iteration path = if let Some ( stem ) = path . file_stem ( ) { Path :: new ( stem ) } else { Path :: new ( " " ) } ; } // Put the extensions in the correct order: left to right extensions . reverse ( ) ; if extensions . is_empty ( ) { try_infer ( original_path , & mut extensions ) ; } ( path , extensions ) }
Extracts extensions from a path,
return both the remaining path and the list of extension objects
Extracts extensions from a path return both the remaining path and the list of extension objects
path
&Path