35 #ifndef INCLUDED_utility_io_zipstream_HPP
36 #define INCLUDED_utility_io_zipstream_HPP
40 #define ZLIB_WINAPI // REQUIRED FOR WINDOWS
46 #include <zlib/zlib.h>
47 #include <zlib/zutil.h>
56 namespace zlib_stream {
76 typename Tr = std::char_traits< Elem >,
77 typename ElemA = std::allocator< Elem >,
78 typename ByteT =
unsigned char,
79 typename ByteAT = std::allocator< ByteT >
82 public std::basic_streambuf< Elem, Tr >
99 using basic_streambuf_type::epptr;
100 using basic_streambuf_type::pbase;
101 using basic_streambuf_type::pptr;
110 size_t memory_level_,
120 std::streamsize
flush();
152 std::streamsize
flush(
int flush_mode );
168 typename Tr = std::char_traits< Elem >,
169 typename ElemA = std::allocator< Elem >,
170 typename ByteT =
unsigned char,
171 typename ByteAT = std::allocator< ByteT >
174 public std::basic_streambuf< Elem, Tr >
190 using basic_streambuf_type::eback;
191 using basic_streambuf_type::egptr;
192 using basic_streambuf_type::gptr;
199 size_t read_buffer_size_,
200 size_t input_buffer_size_
247 typename Tr = std::char_traits< Elem >,
248 typename ElemA = std::allocator< Elem >,
249 typename ByteT =
unsigned char,
250 typename ByteAT = std::allocator< ByteT >
253 virtual public std::basic_ios< Elem, Tr >
274 size_t memory_level_,
277 m_buf( ostream_, level_, strategy_, window_size_, memory_level_, buffer_size_ )
308 typename Tr = std::char_traits< Elem >,
309 typename ElemA = std::allocator< Elem >,
310 typename ByteT =
unsigned char,
311 typename ByteAT = std::allocator< ByteT >
314 virtual public std::basic_ios< Elem, Tr >
331 size_t read_buffer_size_,
332 size_t input_buffer_size_
334 m_buf( ostream_, window_size_, read_buffer_size_, input_buffer_size_ )
387 typename Tr = std::char_traits< Elem >,
388 typename ElemA = std::allocator< Elem >,
389 typename ByteT =
unsigned char,
390 typename ByteAT = std::allocator< ByteT >
394 public std::basic_ostream< Elem, Tr >
404 using ostream_type::flush;
421 bool is_gzip_ =
false,
422 size_t level_ = Z_DEFAULT_COMPRESSION,
424 size_t window_size_ = 15,
425 size_t memory_level_ = 8,
457 flush();
rdbuf()->flush();
return *
this;
465 flush();
rdbuf()->flush_finalize();
479 template<
typename T >
485 static_cast< std::ostream &
>( *this ) << t;
497 static_cast< std::ostream &
>( *this ).put( c );
509 static_cast< std::ostream &
>( *this ).write( str, count );
521 rdbuf()->reset_state();
564 typename Tr = std::char_traits< Elem >,
565 typename ElemA = std::allocator< Elem >,
566 typename ByteT =
unsigned char,
567 typename ByteAT = std::allocator< ByteT >
571 public std::basic_istream< Elem, Tr >
594 size_t window_size_ = 15,
658 #endif // INCLUDED_utility_io_zipstream_HPP
uLong get_crc() const
returns the uncompressed data crc
basic_zip_ostream & write(char const *str, std::streamsize const count)
write a string
ByteAT byte_allocator_type
size_t fill_input_buffer()
std::basic_ostream< Elem, Tr > & ostream_reference
basic_zip_streambuf< Elem, Tr, ElemA, ByteT, ByteAT > zip_streambuf_type
uLong get_crc() const
returns the crc of the input data compressed so far
ByteAT byte_allocator_type
std::basic_ostream< Elem, Tr > & ostream_reference
std::streamsize flush_finalize()
flushes the zip buffer and output buffer and finalize the zip stream
void put_back_from_zip_stream()
byte_type * byte_buffer_type
basic_zip_ostream< char > zip_ostream
basic_zip_istreambase< Elem, Tr, ElemA, ByteT, ByteAT > zip_istreambase_type
uLong get_in_size() const
returns the compressed data size
std::basic_istream< Elem, Tr > istream_type
basic_zip_ostream< Elem, Tr > & zflush()
flush inner buffer and zipper buffer
ostream_reference get_ostream() const
returns a reference to the output stream
uLong get_gzip_data_size() const
return the data size in the file
std::streamsize unzip_from_stream(char_type *, std::streamsize)
std::basic_streambuf< Elem, Tr > basic_streambuf_type
uLong get_out_size() const
returns the number of uncompressed bytes
basic_zip_ostream< Elem, Tr > & zflush_finalize()
flush inner and zipper buffers and finalize zip stream
uLong get_in_size() const
returns the uncompressed data size
std::basic_istream< Elem, Tr > & istream_reference
basic_zip_ostream & put(char const c)
write char
std::vector< byte_type, byte_allocator_type > byte_vector_type
byte_type * byte_buffer_type
static void read_uint32(istream_reference in_, unsigned long &x_)
ElemA char_allocator_type
basic_unzip_streambuf(istream_reference istream_, size_t window_size_, size_t read_buffer_size_, size_t input_buffer_size_)
Construct an unzip stream.
static void put_long_as_uint32(ostream_reference out_, unsigned long x_)
basic_zip_istreambase(istream_reference ostream_, size_t window_size_, size_t read_buffer_size_, size_t input_buffer_size_)
bool is_gzip() const
returns true if it is a gzip
char_vector_type m_buffer
bool zip_to_stream(char_type *, std::streamsize)
uLong get_in_size() const
returns the size (bytes) of the input data compressed so far
uLong get_out_size() const
returns the compressed data size
std::streamsize flush()
flushes the zip buffer and output buffer
Base class for unzip istreams.
istream_reference m_istream
basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT > zip_ostreambase_type
char_vector_type m_buffer
bool check_crc() const
return crc check result
uLong get_crc() const
returns the uncompressed data crc
A stream decorator that takes compressed input and unzips it to a istream.
bool check_data_size() const
return data size check
std::vector< char_type, char_allocator_type > char_vector_type
size_t fill_input_buffer()
uLong get_in_size() const
returns the number of read compressed bytes
basic_zip_ostreambase(ostream_reference ostream_, size_t level_, EStrategy strategy_, size_t window_size_, size_t memory_level_, size_t buffer_size_)
Construct a zip stream.
uLong get_crc() const
returns the crc of the uncompressed data so far
int get_zerr() const
returns the zlib error state
zip_streambuf_type * rdbuf()
returns the underlying zip ostream object
basic_unzip_streambuf< Elem, Tr, ElemA, ByteT, ByteAT > unzip_streambuf_type
std::basic_istream< Elem, Tr > & istream_reference
istream_reference get_istream()
returns the compressed input istream
byte_vector_type m_output_buffer
std::basic_ostream< Elem, Tr > & ostream_reference
uLong get_gzip_crc() const
return the crc value in the file
basic_zip_istream< wchar_t > zip_wistream
z_stream & get_zip_stream()
returns the zlib stream structure
unzip_streambuf_type * rdbuf()
returns the underlying unzip istream object
byte_vector_type m_input_buffer
basic_zip_streambuf(ostream_reference ostream_, size_t level_, EStrategy strategy_, size_t window_size_, size_t memory_level_, size_t buffer_size_)
Construct a zip stream.
int get_zerr() const
returns the latest zlib error status
std::basic_streambuf< Elem, Tr > basic_streambuf_type
void reset_state()
resets the zip stream and zeros the crc
std::vector< char_type, char_allocator_type > char_vector_type
std::basic_istream< Elem, Tr > & istream_reference
bool reset_zip_stream()
if end of stream, reset the zip stream and add header
basic_zip_ostream(ostream_reference ostream_, bool is_gzip_=false, size_t level_=Z_DEFAULT_COMPRESSION, EStrategy strategy_=DefaultStrategy, size_t window_size_=15, size_t memory_level_=8, size_t buffer_size_=default_buffer_size)
Constructs a zipper ostream decorator.
basic_zip_ostream< wchar_t > zip_wostream
bool is_gzip() const
returns true if it is a gzip file
const size_t default_buffer_size
Default gzip buffer size, change this to suite your needs.
ostream_reference m_ostream
basic_zip_istream(istream_reference istream_, size_t window_size_=15, size_t read_buffer_size_=default_buffer_size, size_t input_buffer_size_=default_buffer_size)
Construct a unzipper stream.
ElemA char_allocator_type
void init()
set global 'init_was_called' to true
std::vector< byte_type, byte_allocator_type > byte_vector_type
bool m_zip_stream_finalized
tracks to see if zip stream was finalized
Base class for zip ostreams.
EStrategy
Compression strategy, see zlib doc.
basic_zip_ostream & operator<<(T const &t)
stream output
A stream decorator that takes raw input and zips it to a ostream.
int get_zerr() const
returns the latest zlib error state
std::basic_ostream< Elem, Tr > ostream_type
int get_zerr() const
returns the zlib error state
uLong get_out_size() const
returns the size (bytes) of the compressed data so far
void read_footer()
reads the gzip footer
basic_zip_istream< char > zip_istream
Altered zipstream library implementation.
unzip_streambuf_type m_buf
uLong get_out_size() const
returns the uncompressed data size
int_type overflow(int_type c)