1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use {
    phf::{phf_set, Set},
};

/// a short list of extensions that can't contain source code.
///
/// If you feel this list should maybe be changed, contact
/// me on miaou or raise an issue.
static BINARY_EXTENSIONS: Set<&'static str> = phf_set! {
    "a",
    "aif", "AIF",
    "ap_",
    "apk",
    "bak", "BAK",
    "bin", "BIN",
    "bmp", "BMP",
    "bzip", "BZIP",
    "bzip2", "BZIP2",
    "cab", "CAB",
    "class",
    "com", "COM",
    "crx",
    "dat", "DAT",
    "db",  "DB",
    "dbf", "DBF",
    "deb",
    "doc", "DOC",
    "docx", "DOCX",
    "eps", "EPS",
    "exe", "EXE",
    "dll", "DLL",
    "gif", "GIF",
    "gz",
    "gzip",
    "ico", "ICO",
    "iso", "ISO",
    "jar", "JAR",
    "jpg", "JPG",
    "jpeg", "JPEG",
    "lz4", "LZ4",
    "mdb", "MDB",
    "mp3", "MP3",
    "mp4", "MP4",
    "mpa", "MPa",
    "mpg", "MPG",
    "mpeg", "MPEG",
    "msi", "MSI",
    "o",
    "odf", "ODF",
    "odp", "ODP",
    "ods", "ODS",
    "odt", "ODT",
    "ogg", "OGG",
    "pdb",
    "pdf", "PDF",
    "pkg", "PKG",
    "png", "PNG",
    "ppt", "PPT",
    "pptx", "PPTX",
    "psd", "PSD",
    "ps", "PS",
    "rar", "RAR",
    "rpm", "RPM",
    "rsrc",
    "rtf",
    "so",
    "tar",
    "tar.gz",
    "ttf", "TTF",
    "tgz", "TGZ",
    "xls", "XLS",
    "xlsx", "XLSX",
    "vob", "VOB",
    "vsd", "VSD",
    "vsdx", "VSDX",
    "war", "WAR",
    "wasm",
    "wav", "WAV",
    "woff", "WOFF",
    "woff2", "WOFF2",
    "zip", "ZIP",
    "z", "Z",
};

/// tells whether the file extension is one of a file format
/// which shouln't be searched as text
pub fn is_known_binary(ext: &str) -> bool {
    BINARY_EXTENSIONS.contains(ext)
}