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
use crate::Mime;
use fnv::FnvHashMap;

#[cfg(not(feature = "with-gpl-data"))]
use super::runtime;

fn aliases() -> &'static str {
    #[cfg(feature = "with-gpl-data")]
    return tree_magic_db::aliases();
    #[cfg(not(feature = "with-gpl-data"))]
    return runtime::aliases();
}

fn subclasses() -> &'static str {
    #[cfg(feature = "with-gpl-data")]
    return tree_magic_db::subclasses();
    #[cfg(not(feature = "with-gpl-data"))]
    return runtime::subclasses();
}

pub fn get_aliaslist() -> FnvHashMap<Mime, Mime> {
    aliases()
        .lines()
        .filter(|line| !line.is_empty())
        .map(|line| {
            let mut parts = line.split_whitespace();
            let a = parts.next().unwrap();
            let b = parts.next().unwrap();
            (a, b)
        })
        .collect()
}

/// Get list of supported MIME types
pub fn get_supported() -> Vec<Mime> {
    super::ALL_RULES.keys().cloned().collect()
}

/// Get list of parent -> child subclass links
pub fn get_subclasses() -> Vec<(Mime, Mime)> {
    subclasses()
        .lines()
        .filter(|line| !line.is_empty())
        .map(|line| {
            let mut parts = line.split_whitespace();

            let child = parts.next().unwrap();
            let child = super::ALIASES.get(child).copied().unwrap_or(child);

            let parent = parts.next().unwrap();
            let parent = super::ALIASES.get(parent).copied().unwrap_or(parent);

            (parent, child)
        })
        .collect()
}