23 :
public std::exception
32 _msg +=
"Z_STREAM_ERROR: ";
35 _msg +=
"Z_DATA_ERROR: ";
38 _msg +=
"Z_MEM_ERROR: ";
41 _msg +=
"Z_VERSION_ERROR: ";
44 _msg +=
"Z_BUF_ERROR: ";
47 std::ostringstream oss;
49 _msg +=
"[" + oss.str() +
"]: ";
70 this->zalloc = Z_NULL;
72 this->opaque = Z_NULL;
77 this->next_in = Z_NULL;
78 ret = inflateInit2(
this, 15+32);
82 ret = deflateInit2(
this, _level, Z_DEFLATED, 15+16, 8, Z_DEFAULT_STRATEGY);
84 if (ret != Z_OK)
throw Exception(
this, ret);
104 :
public std::streambuf
136 if (this->gptr() == this->egptr())
139 char * out_buff_free_start =
out_buff;
155 unsigned char b0 = *
reinterpret_cast< unsigned char *
>(
in_buff_start);
156 unsigned char b1 = *
reinterpret_cast< unsigned char *
>(
in_buff_start + 1);
161 && ((b0 == 0x1F && b1 == 0x8B)
162 || (b0 == 0x78 && (b1 == 0x01
181 zstrm_p->next_out =
reinterpret_cast< decltype(
zstrm_p-
>next_out) >(out_buff_free_start);
183 int ret = inflate(
zstrm_p, Z_NO_FLUSH);
189 out_buff_free_start =
reinterpret_cast< decltype(out_buff_free_start)
>(
zstrm_p->next_out);
192 if (ret == Z_STREAM_END)
198 }
while (out_buff_free_start ==
out_buff);
204 return this->gptr() == this->egptr()
206 : traits_type::to_int_type(*this->gptr());
224 :
public std::streambuf
230 zstrm_p(new detail::z_stream_wrapper(false, _level)),
245 while (ret != Z_STREAM_END && ret != Z_BUF_ERROR)
250 if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR)
throw Exception(
zstrm_p, ret);
280 virtual std::streambuf::int_type
overflow(std::streambuf::int_type c = traits_type::eof())
282 zstrm_p->next_in =
reinterpret_cast< decltype(
zstrm_p-
>next_in) >(pbase());
283 zstrm_p->avail_in = (uInt)(pptr() - pbase());
289 setp(
nullptr,
nullptr);
290 return traits_type::eof();
294 return traits_type::eq_int_type(c, traits_type::eof()) ? traits_type::eof() : sputc((
char)c);
300 if (! pptr())
return -1;
319 :
public std::istream
325 exceptions(std::ios_base::badbit);
330 exceptions(std::ios_base::badbit);
339 :
public std::ostream
345 exceptions(std::ios_base::badbit);
350 exceptions(std::ios_base::badbit);
361 template <
typename FStream_Type >
365 :
_fs(filename, mode)
377 explicit ifstream(
const std::string& filename, std::ios_base::openmode mode = std::ios_base::in)
381 exceptions(std::ios_base::badbit);
385 if (rdbuf())
delete rdbuf();
394 explicit ofstream(
const std::string& filename, std::ios_base::openmode mode = std::ios_base::out)
398 exceptions(std::ios_base::badbit);
402 if (rdbuf())
delete rdbuf();
Exception class thrown by failed zlib operations.
const char * what() const NOEXCEPT
Exception(const std::string msg)
Exception(z_stream *zstrm_p, int ret)
z_stream_wrapper(bool _is_input=true, int _level=Z_DEFAULT_COMPRESSION)
ifstream(const std::string &filename, std::ios_base::openmode mode=std::ios_base::in)
istream(std::istream &is)
istream(std::streambuf *sbuf_p)
istreambuf & operator=(const istreambuf &)=delete
virtual std::streambuf::int_type underflow()
istreambuf(const istreambuf &)=delete
static const std::size_t default_buff_size
detail::z_stream_wrapper * zstrm_p
istreambuf(std::streambuf *_sbuf_p, std::size_t _buff_size=default_buff_size, bool _auto_detect=true)
ofstream(const std::string &filename, std::ios_base::openmode mode=std::ios_base::out)
ostream(std::streambuf *sbuf_p)
ostream(std::ostream &os)
int deflate_loop(int flush)
ostreambuf(std::streambuf *_sbuf_p, std::size_t _buff_size=default_buff_size, int _level=Z_DEFAULT_COMPRESSION)
detail::z_stream_wrapper * zstrm_p
static const std::size_t default_buff_size
ostreambuf(const ostreambuf &)=delete
ostreambuf & operator=(const ostreambuf &)=delete
virtual std::streambuf::int_type overflow(std::streambuf::int_type c=traits_type::eof())
strict_fstream_holder(const std::string &filename, std::ios_base::openmode mode=std::ios_base::in)