SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
magic_header.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <array>
13#include <bit>
14#include <span>
15#include <string>
16#include <type_traits>
17#include <vector>
18
22
23namespace seqan3::detail
24{
25
29{
32
34 static constexpr std::array<char, 3> magic_header{'\x1f', '\x8b', '\x08'};
35};
36
40{
43
45 static constexpr std::array<char, 3> magic_header{'\x42', '\x5a', '\x68'};
46};
47
51{
54
56 static constexpr std::array<char, 4> magic_header{'\x28', '\xb5', '\x2f', '\xfd'};
57};
58
62{
65
68 // ID1 ID2 CM
72 // FLG [MTIME ] XFL OS [XLEN ]
73 '\x04',
74 '\x00',
75 '\x00',
76 '\x00',
77 '\x00',
78 '\x00',
79 '\xff',
80 '\x06',
81 '\x00',
82 // B C [SLEN ] [BSIZE ]
83 '\x42',
84 '\x43',
85 '\x02',
86 '\x00',
87 '\x00',
88 '\x00'};
89
94 template <typename char_t, size_t extend>
96 {
97 static_assert(std::equality_comparable_with<char_t, char>,
98 "The given char type of the span must be comparable with char.");
99
100 static constexpr auto id1_pos = std::endian::native == std::endian::little ? 10 : 11;
101
102 return (header[0] == magic_header[0] && // GZ_ID1
103 header[1] == magic_header[1] && // GZ_ID2
104 header[2] == magic_header[2] && // GZ_CM
105 (header[3] & magic_header[3]) != 0 && // FLG_FEXTRA
106 header[id1_pos] == magic_header[10] && // BGZF_ID1
107 header[12] == magic_header[12] && // BGZF_ID2
108 header[13] == magic_header[13] && // BGZF_SLEN
109 header[id1_pos + 4] == magic_header[14]); // BGZF_XLEN
110 }
111};
112
117#if defined(SEQAN3_HAS_ZLIB)
118 ,
121#endif // defined(SEQAN3_HAS_ZLIB)
122#if defined(SEQAN3_HAS_BZIP2)
123 ,
125#endif // defined(SEQAN3_HAS_BZIP2)
126#if SEQAN3_HAS_ZSTD
127 ,
129#endif // SEQAN3_HAS_ZSTD
130 >;
131
132} // namespace seqan3::detail
pack_traits::drop_front< void > compression_formats
A seqan3::type_list containing the available compression formats.
Definition magic_header.hpp:130
typename decltype(detail::drop_front< pack_t... >())::type drop_front
Return a seqan3::type_list of all the types in the type pack, except the first.
Definition type_pack/traits.hpp:305
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
A tag signifying a bgzf compressed file.
Definition magic_header.hpp:62
static std::vector< std::string > file_extensions
The valid file extension for bgzf compression.
Definition magic_header.hpp:64
static bool validate_header(std::span< char_t, extend > header)
Checks if the given header is a bgzf header.
Definition magic_header.hpp:95
static constexpr std::array< char, 18 > magic_header
The magic byte sequence to disambiguate bgzf compressed files.
Definition magic_header.hpp:67
A tag signifying a bz2 compressed file.
Definition magic_header.hpp:40
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate bz2 compressed files.
Definition magic_header.hpp:45
static std::vector< std::string > file_extensions
The valid file extension for bz2 compression.
Definition magic_header.hpp:42
A tag signifying a gz compressed file.
Definition magic_header.hpp:29
static std::vector< std::string > file_extensions
The valid file extension for gz compression.
Definition magic_header.hpp:31
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate gz compressed files.
Definition magic_header.hpp:34
A tag signifying a zstd compressed file.
Definition magic_header.hpp:51
static std::vector< std::string > file_extensions
The valid file extension for zstd compression.
Definition magic_header.hpp:53
static constexpr std::array< char, 4 > magic_header
The magic byte sequence to disambiguate zstd compressed files.
Definition magic_header.hpp:56
Provides type traits for working with templates.
Provides various traits for template packs.
Provides concepts that do not have equivalents in C++20.
Hide me