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
/// Returns whether a buffer is an ePub.
pub fn is_epub(buf: &[u8]) -> bool {
    buf.len() > 57
        && buf[0] == 0x50
        && buf[1] == 0x4B
        && buf[2] == 0x3
        && buf[3] == 0x4
        && buf[30] == 0x6D
        && buf[31] == 0x69
        && buf[32] == 0x6D
        && buf[33] == 0x65
        && buf[34] == 0x74
        && buf[35] == 0x79
        && buf[36] == 0x70
        && buf[37] == 0x65
        && buf[38] == 0x61
        && buf[39] == 0x70
        && buf[40] == 0x70
        && buf[41] == 0x6C
        && buf[42] == 0x69
        && buf[43] == 0x63
        && buf[44] == 0x61
        && buf[45] == 0x74
        && buf[46] == 0x69
        && buf[47] == 0x6F
        && buf[48] == 0x6E
        && buf[49] == 0x2F
        && buf[50] == 0x65
        && buf[51] == 0x70
        && buf[52] == 0x75
        && buf[53] == 0x62
        && buf[54] == 0x2B
        && buf[55] == 0x7A
        && buf[56] == 0x69
        && buf[57] == 0x70
}

/// Returns whether a buffer is a mobi.
pub fn is_mobi(buf: &[u8]) -> bool {
    buf.len() > 67
        // BOOK
        && buf[60] == 0x42
        && buf[61] == 0x4F
        && buf[62] == 0x4F
        && buf[63] == 0x4B
        // MOBI
        && buf[64] == 0x4D
        && buf[65] == 0x4F
        && buf[66] == 0x42
        && buf[67] == 0x49
}