File: magic_numbers.hpp

package info (click to toggle)
r-bioc-alabaster.base 1.6.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,652 kB
  • sloc: cpp: 11,377; sh: 29; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (2)
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
#ifndef BYTEME_MAGIC_NUMBERS_HPP
#define BYTEME_MAGIC_NUMBERS_HPP

namespace byteme {

template<typename T>
bool is_zlib(const T* values, size_t n) {
    if (n >= 2 && static_cast<unsigned char>(values[0]) == 0x78) {
        auto level = static_cast<unsigned char>(values[1]);
        // From https://en.wikipedia.org/wiki/List_of_file_signatures
        if (level == 0x01 || level == 0x5e || level == 0x9c || level == 0xda || level == 0x20 || level == 0x7d || level == 0xbb || level == 0xf9) {
            return true;
        }
    }
    return false;
}

template<typename T>
bool is_gzip(const T* values, size_t n) {
    // ommitting the 0x08 requirement as Gzip could be used with non-DEFLATE algorithms.
    return (n >= 2 && static_cast<unsigned char>(values[0]) == 0x1f && static_cast<unsigned char>(values[1]) == 0x8b);
}

}

#endif