/// Infer the file extention by looking for known magic strings
Infer the file extention by looking for known magic strings
Infer the file extention by looking for known magic strings
fn try_infer(path: PathBuf, extensions: &mut Vec<Extension>) {
    fn is_zip(buf: &[u8]) -> bool {
        buf.len() > 3
            && buf[0] == 0x50
            && buf[1] == 0x4B
            && (buf[2] == 0x3 || buf[2] == 0x5 || buf[2] == 0x7)
            && (buf[3] == 0x4 || buf[3] == 0x6 || buf[3] == 0x8)
    }
    fn is_tar(buf: &[u8]) -> bool {
        buf.len() > 261
            && buf[257] == 0x75
            && buf[258] == 0x73
            && buf[259] == 0x74
            && buf[260] == 0x61
            && buf[261] == 0x72
    }
    fn is_gz(buf: &[u8]) -> bool {
        buf.len() > 2 && buf[0] == 0x1F && buf[1] == 0x8B && buf[2] == 0x8
    }
    fn is_bz2(buf: &[u8]) -> bool {
        buf.len() > 2 && buf[0] == 0x42 && buf[1] == 0x5A && buf[2] == 0x68
    }
    fn is_xz(buf: &[u8]) -> bool {
        buf.len() > 5
            && buf[0] == 0xFD
            && buf[1] == 0x37
            && buf[2] == 0x7A
            && buf[3] == 0x58
            && buf[4] == 0x5A
            && buf[5] == 0x00
    }
    fn is_lz(buf: &[u8]) -> bool {
        buf.len() > 3 && buf[0] == 0x4C && buf[1] == 0x5A && buf[2] == 0x49 && buf[3] == 0x50
    }
    let buf = {
        use std::io::Read;
        let mut b = [0; 270];
        std::fs::File::open(&path).unwrap().read(&mut b).unwrap();
        b
    };
    if is_zip(&buf) {
        extensions.push(Extension::new([Zip], "zip"));
    } else if is_tar(&buf) {
        extensions.push(Extension::new([Tar], "tar"));
    } else if is_gz(&buf) {
        extensions.push(Extension::new([Gzip], "gz"));
    } else if is_bz2(&buf) {
        extensions.push(Extension::new([Bzip], "bz2"));
    } else if is_xz(&buf) {
        extensions.push(Extension::new([Lzma], "xz"));
    } else if is_lz(&buf) {
        extensions.push(Extension::new([Lzma], "lz"));
    }
}
fn try_infer ( path : PathBuf , extensions : & mut Vec < Extension > ) { fn is_zip ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 3 && buf [ 0 ] == 0x50 && buf [ 1 ] == 0x4B && ( buf [ 2 ] == 0x3 || buf [ 2 ] == 0x5 || buf [ 2 ] == 0x7 ) && ( buf [ 3 ] == 0x4 || buf [ 3 ] == 0x6 || buf [ 3 ] == 0x8 ) } fn is_tar ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 261 && buf [ 257 ] == 0x75 && buf [ 258 ] == 0x73 && buf [ 259 ] == 0x74 && buf [ 260 ] == 0x61 && buf [ 261 ] == 0x72 } fn is_gz ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 2 && buf [ 0 ] == 0x1F && buf [ 1 ] == 0x8B && buf [ 2 ] == 0x8 } fn is_bz2 ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 2 && buf [ 0 ] == 0x42 && buf [ 1 ] == 0x5A && buf [ 2 ] == 0x68 } fn is_xz ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 5 && buf [ 0 ] == 0xFD && buf [ 1 ] == 0x37 && buf [ 2 ] == 0x7A && buf [ 3 ] == 0x58 && buf [ 4 ] == 0x5A && buf [ 5 ] == 0x00 } fn is_lz ( buf : & [ u8 ] ) -> bool { buf . len ( ) > 3 && buf [ 0 ] == 0x4C && buf [ 1 ] == 0x5A && buf [ 2 ] == 0x49 && buf [ 3 ] == 0x50 } let buf = { use std :: io :: Read ; let mut b = [ 0 ; 270 ] ; std :: fs :: File :: open ( & path ) . unwrap ( ) . read ( & mut b ) . unwrap ( ) ; b } ; if is_zip ( & buf ) { extensions . push ( Extension :: new ( [ Zip ] , " " ) ) ; } else if is_tar ( & buf ) { extensions . push ( Extension :: new ( [ Tar ] , " " ) ) ; } else if is_gz ( & buf ) { extensions . push ( Extension :: new ( [ Gzip ] , " " ) ) ; } else if is_bz2 ( & buf ) { extensions . push ( Extension :: new ( [ Bzip ] , " " ) ) ; } else if is_xz ( & buf ) { extensions . push ( Extension :: new ( [ Lzma ] , " " ) ) ; } else if is_lz ( & buf ) { extensions . push ( Extension :: new ( [ Lzma ] , " " ) ) ; } }
Infer the file extention by looking for known magic strings
Infer the file extention by looking for known magic strings
path
PathBuf
extensions
&mut Vec<Extension>