1 #ifndef _utl_zstream_h_
2 #define _utl_zstream_h_
4 #include <boost/iostreams/stream.hpp>
5 #include <boost/iostreams/filtering_stream.hpp>
6 #include <boost/iostreams/filter/bzip2.hpp>
7 #include <boost/iostreams/filter/gzip.hpp>
8 #include <boost/shared_ptr.hpp>
30 class filtering_stream,
31 class gzip_compressor,
32 class bzip2_compressor
34 struct zfilter :
public filtering_stream {
37 template<
class stream>
39 {
push(strm, ztype); }
43 template<
class stream>
48 if (static_cast<int>(ztype) >= 4)
49 throw std::invalid_argument(
"only zip options allowed for zfilter");
50 switch (static_cast<int>(ztype) & 3) {
54 filtering_stream::push(gzip_compressor());
57 filtering_stream::push(bzip2_compressor());
60 throw std::invalid_argument(
"xzip not implemented yet");
62 filtering_stream::push(strm);
68 boost::iostreams::filtering_istream,
69 boost::iostreams::gzip_decompressor,
70 boost::iostreams::bzip2_decompressor
75 boost::iostreams::filtering_ostream,
76 boost::iostreams::gzip_compressor,
77 boost::iostreams::bzip2_compressor
89 template<
class stream>
97 boost::iostreams::input,
98 boost::iostreams::device_tag,
99 boost::iostreams::closable_tag
104 template<
class istream>
108 template<
class istream>
114 std::streamsize
read(
char*
const s,
const std::streamsize n)
115 {
return boost::iostreams::read(
_impl->_filter, s, n); }
124 typedef boost::iostreams::stream<zstream_source>
zistream;
133 template<
class stream>
141 boost::iostreams::output,
142 boost::iostreams::device_tag,
143 boost::iostreams::closable_tag,
144 boost::iostreams::flushable_tag
149 template<
class ostream>
153 template<
class ostream>
159 std::streamsize
write(
const char*
const s,
const std::streamsize n)
160 {
return boost::iostreams::write(
_impl->_filter, s, n); }
171 typedef boost::iostreams::stream<zstream_sink>
zostream;
boost::iostreams::stream< zstream_source > zistream
std::streamsize read(char *const s, const std::streamsize n)
zstream_sink(ostream &os, const zip_type ztype=zip_type::none)
boost::shared_ptr< impl > _impl
void attach(ostream &os, const zip_type ztype=zip_type::none)
bool is(const double a, const double b)
void push(stream &strm, const zip_type ztype)
boost::shared_ptr< impl > _impl
zstream_source(istream &is, const zip_type ztype=zip_type::none)
std::streamsize write(const char *const s, const std::streamsize n)
void attach(istream &is, const zip_type ztype=zip_type::none)
impl(stream &strm, const zip_type ztype)
zfilter< boost::iostreams::filtering_ostream, boost::iostreams::gzip_compressor, boost::iostreams::bzip2_compressor > zofilter
zfilter< boost::iostreams::filtering_istream, boost::iostreams::gzip_decompressor, boost::iostreams::bzip2_decompressor > zifilter
boost::iostreams::stream< zstream_sink > zostream
zfilter(stream &strm, const zip_type ztype)
impl(stream &strm, const zip_type ztype)