cpp-filetype
 
Loading...
Searching...
No Matches
archive.hpp
1#ifndef FILETYPE_TYPES_ARCHIVE_HPP
2#define FILETYPE_TYPES_ARCHIVE_HPP
3
4#include <array>
5#include <cstdint>
6#include "filetype/type.hpp"
7
8namespace filetype {
9namespace archive {
10
11using Type = ::filetype::Type;
12
13//------------------------------------------------------------------------------
14// Archive file type definitions
15//------------------------------------------------------------------------------
16
17// ZIP archive format
18// Magic: 50 4B 03 04 (PK..)
19inline const std::array<uint8_t, 4> ZIP_MAGIC = {0x50, 0x4B, 0x03, 0x04};
20inline const Type TYPE_ZIP{"application/zip", "zip"};
21
22// RAR archive format
23// Magic: 52 61 72 21 1A 07 00 (Rar!..)
24inline const std::array<uint8_t, 7> RAR_MAGIC = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00};
25inline const Type TYPE_RAR{"application/x-rar-compressed", "rar"};
26
27// TAR archive format
28// Magic: 75 73 74 61 72 (ustar) at offset 257
29inline const std::array<uint8_t, 5> TAR_MAGIC = {0x75, 0x73, 0x74, 0x61, 0x72};
30inline const Type TYPE_TAR{"application/x-tar", "tar"};
31
32// 7Z archive format
33// Magic: 37 7A BC AF 27 1C (7z..')
34inline const std::array<uint8_t, 6> SEVEN_Z_MAGIC = {0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C};
35inline const Type TYPE_7Z{"application/x-7z-compressed", "7z"};
36
37// GZ archive format
38// Magic: 1F 8B 08 (GZip)
39inline const std::array<uint8_t, 3> GZ_MAGIC = {0x1F, 0x8B, 0x08};
40inline const Type TYPE_GZ{"application/gzip", "gz"};
41inline const Type TYPE_GZIP{"application/gzip", "gzip"};
42
43// BZ2 archive format
44// Magic: 42 5A 68 (BZh)
45inline const std::array<uint8_t, 3> BZ2_MAGIC = {0x42, 0x5A, 0x68};
46inline const Type TYPE_BZ2{"application/x-bzip2", "bz2"};
47inline const Type TYPE_BZIP2{"application/x-bzip2", "bzip2"};
48
49// XZ archive format
50// Magic: FD 37 7A 58 5A 00
51inline const std::array<uint8_t, 6> XZ_MAGIC = {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00};
52inline const Type TYPE_XZ{"application/x-xz", "xz"};
53
54// Z archive format (compress)
55// Magic: 1F 9D
56inline const std::array<uint8_t, 2> Z_MAGIC = {0x1F, 0x9D};
57inline const Type TYPE_Z{"application/x-compress", "Z"};
58
59// LZ (LZIP) archive format
60// Magic: 4C 5A 49 50 (LZIP)
61inline const std::array<uint8_t, 4> LZ_MAGIC = {0x4C, 0x5A, 0x49, 0x50};
62inline const Type TYPE_LZ{"application/x-lzip", "lz"};
63
64} // namespace archive
65} // namespace filetype
66
67#endif // FILETYPE_TYPES_ARCHIVE_HPP