24#if defined(SEQAN3_HAS_BZIP2)
25# include <seqan3/contrib/stream/bz2_istream.hpp>
27#if defined(SEQAN3_HAS_ZLIB)
28# include <seqan3/contrib/stream/bgzf_istream.hpp>
30# include <seqan3/contrib/stream/gz_istream.hpp>
44template <std::ranges::forward_range ref_t, std::ranges::forward_range query_t>
46 requires std::equality_comparable_with<std::ranges::range_reference_t<ref_t>,
47 std::ranges::range_reference_t<query_t>>
49 auto rit = std::ranges::begin(reference);
50 auto rend = std::ranges::end(reference);
52 auto qit = std::ranges::begin(query);
53 auto qend = std::ranges::end(query);
78template <builtin_
character
char_t>
82 assert(primary_stream.good());
95 size_t read_chars = 0;
96 for (; read_chars < magic_number.size(); ++read_chars)
101 magic_number[read_chars] = *it;
106 for (
size_t i = 0; i < read_chars; ++i)
107 primary_stream.unget();
110 if (filename.has_extension())
111 extension = filename.extension().
string().substr(1);
114 [[maybe_unused]]
auto contains_extension = [](
auto compression_tag,
auto const & extension)
constexpr
117 != std::ranges::end(
decltype(compression_tag)::file_extensions);
123#if defined(SEQAN3_HAS_ZLIB)
125 filename.replace_extension();
127 return {
new contrib::basic_bgzf_istream<char_t>{primary_stream}, stream_deleter_default};
129 throw file_open_error{
"Trying to read from a bgzf file, but no ZLIB available."};
134#if defined(SEQAN3_HAS_ZLIB)
136 filename.replace_extension();
138 return {
new contrib::basic_gz_istream<char_t>{primary_stream}, stream_deleter_default};
140 throw file_open_error{
"Trying to read from a gzipped file, but no ZLIB available."};
145#if defined(SEQAN3_HAS_BZIP2)
147 filename.replace_extension();
149 return {
new contrib::basic_bz2_istream<char_t>{primary_stream}, stream_deleter_default};
151 throw file_open_error{
"Trying to read from a bzipped file, but no libbz2 available."};
156 throw file_open_error{
"Trying to read from a zst'ed file, but SeqAn does not yet support this."};
159 return {&primary_stream, stream_deleter_noop};
163template <builtin_
character
char_t>
Provides stream compression utilities.
bool starts_with(ref_t &&reference, query_t &&query)
Check whether the query range is a prefix of the reference range.
Definition: misc_input.hpp:45
auto make_secondary_istream(std::basic_istream< char_t > &primary_stream, std::filesystem::path &filename) -> std::unique_ptr< std::basic_istream< char_t >, std::function< void(std::basic_istream< char_t > *)> >
Depending on the magic bytes of the given stream, return a decompression stream or forward the primar...
Definition: misc_input.hpp:79
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition: traits.hpp:182
Provides exceptions used in the I/O module.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The <ranges> header from C++20's standard library.
A tag signifying a bgzf compressed file.
Definition: magic_header.hpp:65
static bool validate_header(std::span< char_t, extend > header)
Checks if the given header is a bgzf header.
Definition: magic_header.hpp:98
static constexpr std::array< char, 18 > magic_header
The magic byte sequence to disambiguate bgzf compressed files.
Definition: magic_header.hpp:70
A tag signifying a bz2 compressed file.
Definition: magic_header.hpp:43
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate bz2 compressed files.
Definition: magic_header.hpp:48
A tag signifying a gz compressed file.
Definition: magic_header.hpp:32
static constexpr std::array< char, 3 > magic_header
The magic byte sequence to disambiguate gz compressed files.
Definition: magic_header.hpp:37
static constexpr std::array< char, 4 > magic_header
The magic byte sequence to disambiguate zstd compressed files.
Definition: magic_header.hpp:59
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition: exception.hpp:39
Provides concepts that do not have equivalents in C++20.