SeqAn3 3.1.0-rc.2
The Modern C++ library for sequence analysis.
magic_header.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <array>
16#include <seqan3/std/span>
17#include <string>
19#include <vector>
20
25
26namespace seqan3::detail
27{
28
32{
35 {
36 {"gz"}
37 };
38
40 static constexpr std::array<char, 3> magic_header{'\x1f', '\x8b', '\x08'};
41};
42
46{
49 {
50 {"bz2"}
51 };
52
54 static constexpr std::array<char, 3> magic_header{'\x42', '\x5a', '\x68'};
55};
56
60{
63 {
64 {"zst"}
65 };
66
68 static constexpr std::array<char, 4> magic_header{'\x28', '\xb5', '\x2f', '\xfd'};
69};
70
74{
77 {
78 {"bgzf"}
79 };
80
83 {
84 // ID1 ID2 CM
86 // FLG [MTIME ] XFL OS [XLEN ]
87 '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', '\xff', '\x06', '\x00',
88 // B C [SLEN ] [BSIZE ]
89 '\x42', '\x43', '\x02', '\x00', '\x00', '\x00'
90 };
91
96 template <typename char_t, size_t extend>
98 {
100 "The given char type of the span must be comparable with char.");
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 to_little_endian(*reinterpret_cast<uint16_t const *>(&header[10])) == magic_header[10] && // BGZF_ID1
107 header[12] == magic_header[12] && // BGZF_ID2
108 header[13] == magic_header[13] && // BGZF_SLEN
109 to_little_endian(*reinterpret_cast<uint16_t const *>(&header[14])) == magic_header[14]); // BGZF_XLEN
110 }
111};
112
117 #if defined(SEQAN3_HAS_ZLIB)
120 #endif // defined(SEQAN3_HAS_ZLIB)
121 #if defined(SEQAN3_HAS_BZIP2)
123 #endif // defined(SEQAN3_HAS_BZIP2)
124 #if SEQAN3_HAS_ZSTD
126 #endif // SEQAN3_HAS_ZSTD
127 >;
128
129} // namespace seqan3::detail
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
pack_traits::drop_front< void > compression_formats
A seqan3::type_list containing the available compression formats.
Definition: magic_header.hpp:127
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: traits.hpp:322
constexpr type to_little_endian(type const in) noexcept
Convert the byte encoding of integer values to little-endian byte order.
Definition: to_little_endian.hpp:42
Requires the two operands to be comparable with == and != in both directions.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides std::span from the C++20 standard library.
A tag signifying a bgzf compressed file.
Definition: magic_header.hpp:74
static std::vector< std::string > file_extensions
The valid file extension for bgzf compression.
Definition: magic_header.hpp:77
static bool validate_header(std::span< char_t, extend > header)
Checks if the given header is a bgzf header.
Definition: magic_header.hpp:97
static constexpr std::array< char, 18 > magic_header
The magic byte sequence to disambiguate bgzf compressed files.
Definition: magic_header.hpp:83
A tag signifying a bz2 compressed file.
Definition: magic_header.hpp:46
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate bz2 compressed files.
Definition: magic_header.hpp:54
static std::vector< std::string > file_extensions
The valid file extension for bz2 compression.
Definition: magic_header.hpp:49
A tag signifying a gz compressed file.
Definition: magic_header.hpp:32
static std::vector< std::string > file_extensions
The valid file extension for gz compression.
Definition: magic_header.hpp:35
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate gz compressed files.
Definition: magic_header.hpp:40
A tag signifying a zstd compressed file.
Definition: magic_header.hpp:60
static std::vector< std::string > file_extensions
The valid file extension for zstd compression.
Definition: magic_header.hpp:63
static constexpr std::array< char, 4 > magic_header
The magic byte sequence to disambiguate zstd compressed files.
Definition: magic_header.hpp:68
Provides type traits for working with templates.
Provides utility functions for bit twiddling.
Provides various traits for template packs.
Provides C++20 additions to the type_traits header.