-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathio.h
More file actions
102 lines (85 loc) · 2.46 KB
/
Copy pathio.h
File metadata and controls
102 lines (85 loc) · 2.46 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef MINOCORE_UTIL_IO_H__
#define MINOCORE_UTIL_IO_H__
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/file.hpp>
#include <iostream>
#include <fstream>
#ifdef _BZLIB_H
#include "bzlib.h"
#include <boost/iostreams/filter/bzip2.hpp>
#pragma message("Enabling bzip2 support")
#ifndef EXTERNAL_BOOST_IOSTREAMS
#include "./boost/bzip2.cpp"
#else
#endif
#else
#ifdef VERBOSE_AF
#pragma message("Not enabling bzip2 support")
#endif
#endif
#if defined(LZMA_H) || defined(HAVE_LZMA)
#include "lzma.h"
#include <boost/iostreams/filter/lzma.hpp>
#ifdef VERBOSE_AF
#pragma message("Enabling xz support")
#endif
#ifndef EXTERNAL_BOOST_IOSTREAMS
#include "./boost/lzma.cpp"
#endif
#else
#ifdef VERBOSE_AF
#pragma message("Not Enabling xz support")
#endif
#endif
#ifdef ZSTDLIB_API
#include <boost/iostreams/filter/zstd.hpp>
#ifdef VERBOSE_AF
#pragma message("Enabling zstd support")
#endif
#ifndef EXTERNAL_BOOST_IOSTREAMS
#include "./boost/zstd.cpp"
#endif
#else
#ifdef VERBOSE_AF
#pragma message("Not Enabling zstsd support")
#endif
#endif
#include <boost/algorithm/string/predicate.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#ifndef EXTERNAL_BOOST_IOSTREAMS
#include "./boost/gzip.cpp"
#include "./boost/zlib.cpp"
#endif
namespace minicore {
namespace util {
namespace io {
namespace boost_io = boost::iostreams;
static inline
std::pair<std::unique_ptr<boost_io::filtering_istream>, std::unique_ptr<std::ifstream>>
xopen(std::string path) {
std::pair<std::unique_ptr<boost_io::filtering_istream>, std::unique_ptr<std::ifstream>> ret;
ret.first.reset(new boost_io::filtering_istream);
if(boost::algorithm::ends_with(path, ".gz")) {
ret.first->push(boost_io::gzip_decompressor());
#ifdef LZMA_H
} else if(boost::algorithm::ends_with(path, ".xz")) {
ret.first->push(boost_io::lzma_decompressor());
#endif
#ifdef _BZLIB_H
} else if(boost::algorithm::ends_with(path, ".bz2")) {
ret.first->push(boost_io::bzip2_decompressor());
#endif
#ifdef ZSTDLIB_API
} else if(boost::algorithm::ends_with(path, ".zst")) {
ret.first->push(boost_io::basic_zstd_decompressor());
#endif
}
ret.second.reset(new std::ifstream(path, std::ios_base::in | std::ios_base::binary));
ret.first->push(*ret.second);
return ret;
}
} // namespace io
}
} // namespace minicore
#endif /* MINOCORE_UTIL_IO_H__ */