29 #ifndef CDPL_UTIL_COMPRESSIONSTREAMS_HPP
30 #define CDPL_UTIL_COMPRESSIONSTREAMS_HPP
34 #include <boost/iostreams/copy.hpp>
35 #include <boost/iostreams/filtering_stream.hpp>
36 #include <boost/iostreams/filter/gzip.hpp>
37 #include <boost/iostreams/filter/bzip2.hpp>
56 template <CompressionAlgo CompAlgo>
75 template <CompressionAlgo CompAlgo,
typename StreamType>
82 typedef typename StreamType::int_type
int_type;
83 typedef typename StreamType::pos_type
pos_type;
84 typedef typename StreamType::off_type
off_type;
85 typedef std::basic_istream<char_type, traits_type>
IStreamType;
86 typedef std::basic_ostream<char_type, traits_type>
OStreamType;
100 typedef std::basic_filebuf<char_type, traits_type> FileBufType;
102 FileBufType tmpFileBuf;
105 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
110 typedef typename std::basic_istream<CharT, TraitsT> StreamType;
120 void open(StreamType& stream);
124 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
129 typedef typename std::basic_ostream<CharT, TraitsT> StreamType;
141 void open(StreamType& stream);
149 template <CompressionAlgo CompAlgo,
typename CharT =
char,
typename TraitsT = std::
char_traits<CharT> >
154 typedef typename std::basic_iostream<CharT, TraitsT> StreamType;
166 void open(StreamType& stream);
186 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
188 StreamType(&tmpFileBuf)
191 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
194 if (!tmpFileBuf.close())
195 this->setstate(std::ios_base::failbit);
200 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
205 if (!tmpFileBuf.open(tmp_file_rem.
getPath().c_str(),
206 std::ios_base::in | std::ios_base::out |
207 std::ios_base::trunc | std::ios_base::binary))
208 this->setstate(std::ios_base::failbit);
210 this->clear(std::ios_base::goodbit);
213 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
218 is.seekg(0, std::ios_base::end);
223 this->setstate(std::ios_base::failbit);
232 boost::iostreams::filtering_stream<boost::iostreams::input, char_type, traits_type> fs;
237 boost::iostreams::copy(fs, *this->rdbuf());
239 if (this->tmpFileBuf.pubseekpos(0, std::ios_base::in | std::ios_base::out) != 0)
240 this->setstate(std::ios_base::failbit);
242 this->setstate(is.rdstate() | fs.rdstate());
245 template <CDPL::Util::CompressionAlgo CompAlgo,
typename StreamType>
248 if (tmpFileBuf.pubseekpos(0, std::ios_base::in) != 0) {
249 this->setstate(std::ios_base::failbit);
253 boost::iostreams::filtering_stream<boost::iostreams::output, char_type, traits_type> fs;
258 boost::iostreams::copy(*this->rdbuf(), fs);
260 this->setstate(os.rdstate() | fs.rdstate());
265 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
269 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
275 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
281 this->decompInput(stream);
284 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
287 this->closeTmpFile();
292 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
297 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
304 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
309 stream->seekp(outPos);
310 this->compOutput(*stream);
315 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
323 outPos = stream.tellp();
324 this->setstate(stream.rdstate());
327 this->stream = &stream;
330 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
334 stream->seekp(outPos);
335 this->compOutput(*stream);
343 this->closeTmpFile();
348 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
353 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
360 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
365 stream->seekp(outPos);
366 this->compOutput(*stream);
371 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
379 outPos = stream.tellp();
380 this->setstate(stream.rdstate());
385 this->decompInput(stream);
388 this->stream = &stream;
391 template <CDPL::Util::CompressionAlgo CompAlgo,
typename CharT,
typename TraitsT>
395 stream->seekp(outPos);
396 this->compOutput(*stream);
404 this->closeTmpFile();
Declaration of filesystem-related functions.
Definition of the class CDPL::Util::FileRemover.
Definition: CompressionStreams.hpp:151
void close()
Definition: CompressionStreams.hpp:392
CompressedIOStream()
Definition: CompressionStreams.hpp:349
StreamType::char_type char_type
Definition: CompressionStreams.hpp:155
~CompressedIOStream()
Definition: CompressionStreams.hpp:361
StreamType::off_type off_type
Definition: CompressionStreams.hpp:159
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:156
void open(StreamType &stream)
Definition: CompressionStreams.hpp:372
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:158
StreamType::int_type int_type
Definition: CompressionStreams.hpp:157
Definition: CompressionStreams.hpp:126
StreamType::int_type int_type
Definition: CompressionStreams.hpp:132
~CompressionOStream()
Definition: CompressionStreams.hpp:305
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:131
CompressionOStream()
Definition: CompressionStreams.hpp:293
StreamType::off_type off_type
Definition: CompressionStreams.hpp:134
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:133
StreamType::char_type char_type
Definition: CompressionStreams.hpp:130
void close()
Definition: CompressionStreams.hpp:331
void open(StreamType &stream)
Definition: CompressionStreams.hpp:316
Definition: CompressionStreams.hpp:77
std::basic_istream< char_type, traits_type > IStreamType
Definition: CompressionStreams.hpp:85
void decompInput(IStreamType &is)
Definition: CompressionStreams.hpp:214
StreamType::off_type off_type
Definition: CompressionStreams.hpp:84
StreamType::char_type char_type
Definition: CompressionStreams.hpp:80
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:81
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:83
void openTmpFile()
Definition: CompressionStreams.hpp:201
std::basic_ostream< char_type, traits_type > OStreamType
Definition: CompressionStreams.hpp:86
void closeTmpFile()
Definition: CompressionStreams.hpp:192
StreamType::int_type int_type
Definition: CompressionStreams.hpp:82
CompressionStreamBase()
Definition: CompressionStreams.hpp:187
void compOutput(OStreamType &os)
Definition: CompressionStreams.hpp:246
virtual ~CompressionStreamBase()
Definition: CompressionStreams.hpp:91
Definition: CompressionStreams.hpp:107
void open(StreamType &stream)
Definition: CompressionStreams.hpp:276
StreamType::char_type char_type
Definition: CompressionStreams.hpp:111
StreamType::traits_type traits_type
Definition: CompressionStreams.hpp:112
StreamType::int_type int_type
Definition: CompressionStreams.hpp:113
StreamType::off_type off_type
Definition: CompressionStreams.hpp:115
StreamType::pos_type pos_type
Definition: CompressionStreams.hpp:114
void close()
Definition: CompressionStreams.hpp:285
DecompressionIStream()
Definition: CompressionStreams.hpp:266
Definition: FileRemover.hpp:44
const std::string & getPath() const
CDPL_UTIL_API std::string genCheckedTempFilePath(const std::string &dir="", const std::string &ptn="%%%%-%%%%-%%%%-%%%%")
CompressedIOStream< GZIP > GZipIOStream
Definition: CompressionStreams.hpp:178
CompressionAlgo
Definition: CompressionStreams.hpp:50
@ BZIP2
Definition: CompressionStreams.hpp:53
@ GZIP
Definition: CompressionStreams.hpp:52
DecompressionIStream< GZIP > GZipIStream
Definition: CompressionStreams.hpp:174
CompressionOStream< BZIP2 > BZip2OStream
Definition: CompressionStreams.hpp:177
DecompressionIStream< BZIP2 > BZip2IStream
Definition: CompressionStreams.hpp:175
CompressionOStream< GZIP > GZipOStream
Definition: CompressionStreams.hpp:176
CompressedIOStream< BZIP2 > BZip2IOStream
Definition: CompressionStreams.hpp:179
The namespace of the Chemical Data Processing Library.
boost::iostreams::bzip2_compressor CompFilter
Definition: CompressionStreams.hpp:72
boost::iostreams::bzip2_decompressor DecompFilter
Definition: CompressionStreams.hpp:71
boost::iostreams::gzip_compressor CompFilter
Definition: CompressionStreams.hpp:64
boost::iostreams::gzip_decompressor DecompFilter
Definition: CompressionStreams.hpp:63
Definition: CompressionStreams.hpp:57