Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
zipstream.hpp
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/io/zipstream.hpp
11 /// @brief Altered zipstream library header
12 /// @author Jonathan de Halleux (dehalleux@pelikhan.com)
13 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
14 /// @author David Kim (dekim@u.washington.edu)
15 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
16 
17 // zipstream Library License:
18 // --------------------------
19 //
20 // The zlib/libpng License Copyright (c) 2003 Jonathan de Halleux.
21 //
22 // This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
23 //
24 // Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
25 //
26 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
27 //
28 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
29 //
30 // 3. This notice may not be removed or altered from any source distribution
31 //
32 // Author: Jonathan de Halleux, dehalleux@pelikhan.com, 2003
33 
34 
35 #ifndef INCLUDED_utility_io_zipstream_HPP
36 #define INCLUDED_utility_io_zipstream_HPP
37 
38 #ifdef _WIN32
39 #ifndef PYROSETTA
40 #define ZLIB_WINAPI // REQUIRED FOR WINDOWS
41 #endif
42 #endif
43 
44 
45 // Zlib headers
46 #include <zlib/zlib.h>
47 #include <zlib/zutil.h>
48 
49 
50 // C++ headers
51 #include <algorithm>
52 #include <iostream>
53 #include <vector>
54 
55 
56 namespace zlib_stream {
57 
58 
59 /// @brief Default gzip buffer size, change this to suite your needs
60 const size_t default_buffer_size = 921600; // Was 102400; Was 4096;
61 
62 
63 /// Compression strategy, see zlib doc.
65 {
69 };
70 
71 
72 /// @brief A stream decorator that takes raw input and zips it to a ostream.
73 /// @note The class wraps up the inflate method of the zlib library 1.1.4 http://www.gzip.org/zlib/
74 template<
75 typename Elem,
76 typename Tr = std::char_traits< Elem >,
77 typename ElemA = std::allocator< Elem >,
78 typename ByteT = unsigned char,
79 typename ByteAT = std::allocator< ByteT >
80 >
82  public std::basic_streambuf< Elem, Tr >
83 {
84 
85 public:
86 
87  typedef std::basic_streambuf< Elem, Tr > basic_streambuf_type;
88  typedef std::basic_ostream< Elem, Tr > & ostream_reference;
89  typedef Elem char_type;
90  typedef ElemA char_allocator_type;
91  typedef ByteT byte_type;
92  typedef ByteAT byte_allocator_type;
94  typedef std::vector< byte_type, byte_allocator_type > byte_vector_type;
95  typedef std::vector< char_type, char_allocator_type > char_vector_type;
96  typedef Tr traits_type;
97  typedef typename Tr::int_type int_type;
98 
99  using basic_streambuf_type::epptr;
100  using basic_streambuf_type::pbase;
101  using basic_streambuf_type::pptr;
102 
103  /// @brief Construct a zip stream
104  /// @note More info on the following parameters can be found in the zlib documentation
106  ostream_reference ostream_,
107  size_t level_,
108  EStrategy strategy_,
109  size_t window_size_,
110  size_t memory_level_,
111  size_t buffer_size_
112  );
113 
115 
116  int sync();
118 
119  /// @brief flushes the zip buffer and output buffer
120  std::streamsize flush();
121 
122  /// @brief flushes the zip buffer and output buffer and finalize the zip stream
123  /// @details This method should be called at the end of the compression.
124  std::streamsize flush_finalize();
125 
126  /// @brief resets the zip stream and zeros the crc
127  /// @details This method should be called after flush_finalize()
128  /// @deatils to allow future writes
129  void reset_state();
130 
131  /// @brief returns a reference to the output stream
133 
134  /// @brief returns the latest zlib error status
135  int get_zerr() const { return m_err; }
136 
137  /// @brief returns the crc of the input data compressed so far
138  uLong get_crc() const { return m_crc; }
139 
140  /// @brief returns the size (bytes) of the input data compressed so far
141  uLong get_in_size() const { return m_zip_stream.total_in; }
142 
143  /// @brief returns the size (bytes) of the compressed data so far
144  uLong get_out_size() const { return m_zip_stream.total_out; }
145 
146 private:
147 
148  bool zip_to_stream( char_type*, std::streamsize );
149  size_t fill_input_buffer();
150 
151  /// @brief flush the zip buffer using a particular mode and flush output buffer
152  std::streamsize flush( int flush_mode );
153 
155  z_stream m_zip_stream;
156  int m_err;
159  uLong m_crc;
160 
161 }; // basic_zip_streambuf
162 
163 
164 /// @brief A stream decorator that takes compressed input and unzips it to a istream.
165 /// @note The class wraps up the deflate method of the zlib library 1.1.4 http://www.gzip.org/zlib/
166 template<
167 typename Elem,
168 typename Tr = std::char_traits< Elem >,
169 typename ElemA = std::allocator< Elem >,
170 typename ByteT = unsigned char,
171 typename ByteAT = std::allocator< ByteT >
172 >
174  public std::basic_streambuf< Elem, Tr >
175 {
176 
177 public:
178 
179  typedef std::basic_streambuf< Elem, Tr > basic_streambuf_type;
180  typedef std::basic_istream< Elem, Tr > & istream_reference;
181  typedef Elem char_type;
182  typedef ElemA char_allocator_type;
183  typedef ByteT byte_type;
184  typedef ByteAT byte_allocator_type;
186  typedef std::vector< byte_type, byte_allocator_type > byte_vector_type;
187  typedef std::vector< char_type, char_allocator_type > char_vector_type;
188  typedef typename Tr::int_type int_type;
189 
190  using basic_streambuf_type::eback;
191  using basic_streambuf_type::egptr;
192  using basic_streambuf_type::gptr;
193 
194  /// @brief Construct an unzip stream
195  /// @note More info on the following parameters can be found in the zlib documentation
197  istream_reference istream_,
198  size_t window_size_,
199  size_t read_buffer_size_,
200  size_t input_buffer_size_
201  );
202 
204 
206 
207  /// @brief returns the compressed input istream
209 
210  /// @brief returns the zlib stream structure
211  z_stream & get_zip_stream() { return m_zip_stream; }
212 
213  /// @brief returns the latest zlib error state
214  int get_zerr() const { return m_err; }
215 
216  /// @brief returns the crc of the uncompressed data so far
217  uLong get_crc() const { return m_crc; }
218 
219  /// @brief returns the number of uncompressed bytes
220  uLong get_out_size() const { return m_zip_stream.total_out; }
221 
222  /// @brief returns the number of read compressed bytes
223  uLong get_in_size() const { return m_zip_stream.total_in; }
224 
225 private:
226 
228 
229  std::streamsize unzip_from_stream( char_type*, std::streamsize );
230 
231  size_t fill_input_buffer();
232 
234  z_stream m_zip_stream;
235  int m_err;
238  uLong m_crc;
239 
240 }; // basic_unzip_streambuf
241 
242 
243 /// @brief Base class for zip ostreams
244 /// @note Contains a basic_zip_streambuf
245 template<
246 typename Elem,
247 typename Tr = std::char_traits< Elem >,
248 typename ElemA = std::allocator< Elem >,
249 typename ByteT = unsigned char,
250 typename ByteAT = std::allocator< ByteT >
251 >
253  virtual public std::basic_ios< Elem, Tr >
254 {
255 
256 public:
257 
258  typedef std::basic_ostream<Elem, Tr> & ostream_reference;
259  typedef basic_zip_streambuf<
260  Elem,
261  Tr,
262  ElemA,
263  ByteT,
264  ByteAT
266 
267  /// @brief Construct a zip stream
268  /// @note More info on the following parameters can be found in the zlib documentation.
270  ostream_reference ostream_,
271  size_t level_,
272  EStrategy strategy_,
273  size_t window_size_,
274  size_t memory_level_,
275  size_t buffer_size_
276  ) :
277  m_buf( ostream_, level_, strategy_, window_size_, memory_level_, buffer_size_ )
278  {
279  this->init( &m_buf );
280  }
281 
282  /// @brief returns the underlying zip ostream object
283  zip_streambuf_type * rdbuf() { return &m_buf; }
284 
285  /// @brief returns the zlib error state
286  int get_zerr() const { return m_buf.get_err(); }
287 
288  /// @brief returns the uncompressed data crc
289  uLong get_crc() const { return m_buf.get_crc(); }
290 
291  /// @brief returns the compressed data size
292  uLong get_out_size() const { return m_buf.get_out_size(); }
293 
294  /// @brief returns the uncompressed data size
295  uLong get_in_size() const { return m_buf.get_in_size(); }
296 
297 private:
298 
300 
301 }; // basic_zip_ostreambase
302 
303 
304 /// @brief Base class for unzip istreams
305 /// @note Contains a basic_unzip_streambuf
306 template<
307 typename Elem,
308 typename Tr = std::char_traits< Elem >,
309 typename ElemA = std::allocator< Elem >,
310 typename ByteT = unsigned char,
311 typename ByteAT = std::allocator< ByteT >
312 >
314  virtual public std::basic_ios< Elem, Tr >
315 {
316 
317 public:
318 
319  typedef std::basic_istream< Elem, Tr > & istream_reference;
320  typedef basic_unzip_streambuf<
321  Elem,
322  Tr,
323  ElemA,
324  ByteT,
325  ByteAT
327 
329  istream_reference ostream_,
330  size_t window_size_,
331  size_t read_buffer_size_,
332  size_t input_buffer_size_
333  ) :
334  m_buf( ostream_, window_size_, read_buffer_size_, input_buffer_size_ )
335  {
336  this->init( &m_buf );
337  }
338 
339  /// @brief returns the underlying unzip istream object
341 
342  /// @brief returns the zlib error state
343  int get_zerr() const { return m_buf.get_zerr(); }
344 
345  /// @brief returns the uncompressed data crc
346  uLong get_crc() const { return m_buf.get_crc(); }
347 
348  /// @brief returns the uncompressed data size
349  uLong get_out_size() const { return m_buf.get_out_size(); }
350 
351  /// @brief returns the compressed data size
352  uLong get_in_size() const { return m_buf.get_in_size(); }
353 
354 private:
355 
357 
358 }; // basic_zip_istreambase
359 
360 
361 /// @brief A zipper ostream
362 ///
363 /// @remarks
364 ///
365 /// This class is a ostream decorator that behaves 'almost' like any other ostream.
366 ///
367 /// At construction, it takes any ostream that shall be used to output of the compressed data.
368 ///
369 /// When finished, you need to call the special method zflush or call the destructor
370 /// to flush all the intermidiate streams.
371 ///
372 /// Example:
373 /// \code
374 /// // creating the target zip string, could be a fstream
375 /// ostringstream ostringstream_;
376 /// // creating the zip layer
377 /// zip_ostream zipper(ostringstream_);
378 ///
379 ///
380 /// // writing data
381 /// zipper<<f<<" "<<d<<" "<<ui<<" "<<ul<<" "<<us<<" "<<c<<" "<<dum;
382 /// // zip ostream needs special flushing...
383 /// zipper.zflush();
384 /// \endcode
385 template<
386 typename Elem,
387 typename Tr = std::char_traits< Elem >,
388 typename ElemA = std::allocator< Elem >,
389 typename ByteT = unsigned char,
390 typename ByteAT = std::allocator< ByteT >
391 >
393  public basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >,
394  public std::basic_ostream< Elem, Tr >
395 {
396 
397 public:
398 
400  typedef std::basic_ostream< Elem, Tr > ostream_type;
401  typedef std::basic_ostream< Elem, Tr > & ostream_reference;
402  typedef Elem char_type;
403 
404  using ostream_type::flush;
406 
407  /// @brief Constructs a zipper ostream decorator
408  ///
409  /// @param ostream_ ostream where the compressed output is written
410  /// @param is_gzip_ true if gzip header and footer have to be added
411  /// @param level_ level of compression 0, bad and fast, 9, good and slower,
412  /// @param strategy_ compression strategy
413  /// @param window_size_ see zlib doc
414  /// @param memory_level_ see zlib doc
415  /// @param buffer_size_ the buffer size used to zip data
416  ///
417  /// @note When is_gzip_ is true, a gzip header and footer is automatically added
419  ostream_reference ostream_,
420  // int open_mode = std::ios::out,
421  bool is_gzip_ = false,
422  size_t level_ = Z_DEFAULT_COMPRESSION,
423  EStrategy strategy_ = DefaultStrategy,
424  size_t window_size_ = 15,
425  size_t memory_level_ = 8,
426  size_t buffer_size_ = default_buffer_size
427  ) :
429  ostream_,
430  level_,
431  strategy_,
432  window_size_,
433  memory_level_,
434  buffer_size_
435  ),
436  ostream_type( rdbuf() ),
437  m_is_gzip( is_gzip_ ),
438  m_zip_stream_finalized( false )
439  {
440  if ( m_is_gzip ) add_header();
441  }
442 
444  {
445  // adding a footer is not necessary here, as it will be
446  // taken care of during the last zflush_finalize()
447  // called by the higher level close() routines
448  }
449 
450  /// @brief returns true if it is a gzip
451  bool is_gzip() const { return m_is_gzip; }
452 
453  /// @brief flush inner buffer and zipper buffer
456  {
457  flush(); rdbuf()->flush(); return *this;
458  }
459 
460  /// @brief flush inner and zipper buffers and finalize zip stream
463  {
464 
465  flush(); rdbuf()->flush_finalize();
466 
467  if ( m_is_gzip && ( rdbuf()->get_zerr() == Z_STREAM_END ) && ( !m_zip_stream_finalized ) ) {
468  add_footer(); // writes crc trailer to end the current zip stream
469  flush();
470  m_zip_stream_finalized = true;
471  }
472 
473  return *this;
474  }
475 
476  /// @brief stream output
477  /// @details if zip stream has been finalized, will reset
478  /// @details the stream and add header if necessary
479  template< typename T >
480  inline
482  operator <<( T const & t )
483  {
485  static_cast< std::ostream & >( *this ) << t;
486  return *this;
487  }
488 
489  /// @brief write char
490  /// @details if zip stream has been finalized, will reset
491  /// @details the stream and add header if necessary
492  inline
494  put( char const c )
495  {
497  static_cast< std::ostream & >( *this ).put( c );
498  return *this;
499  }
500 
501  /// @brief write a string
502  /// @details if zip stream has been finalized, will reset
503  /// @details the stream and add header if necessary
504  inline
506  write( char const * str, std::streamsize const count )
507  {
509  static_cast< std::ostream & >( *this ).write( str, count );
510  return *this;
511  }
512 
513 private:
514 
515  /// @brief if end of stream, reset the zip stream and add header
516  inline
517  bool
519  {
520  if ( rdbuf()->get_zerr() == Z_STREAM_END ) {
521  rdbuf()->reset_state();
522  add_header();
523  m_zip_stream_finalized = false;
524  return true;
525  }
526  return false;
527  }
528 
529  static void put_long_as_uint32( ostream_reference out_, unsigned long x_ );
530 
531  void add_header();
532  void add_footer();
533 
534  bool m_is_gzip;
535 
536  /// @brief tracks to see if zip stream was finalized
537  /// @details set to true during zflush_finalize()
538  /// @details set to false during reset_state()
540 
541 }; // basic_zip_ostream
542 
543 
544 /// @brief A zipper istream
545 ///
546 /// @remarks
547 ///
548 /// This class is a istream decorator that behaves 'almost' like any other ostream.
549 ///
550 /// At construction, it takes any istream that shall be used to input of the compressed data.
551 ///
552 /// Simlpe example:
553 /// \code
554 /// // create a stream on zip string
555 /// istringstream istringstream_( ostringstream_.str());
556 /// // create unzipper istream
557 /// zip_istream unzipper( istringstream_);
558 ///
559 /// // read and unzip
560 /// unzipper>>f_r>>d_r>>ui_r>>ul_r>>us_r>>c_r>>dum_r;
561 /// \endcode
562 template<
563 typename Elem,
564 typename Tr = std::char_traits< Elem >,
565 typename ElemA = std::allocator< Elem >,
566 typename ByteT = unsigned char,
567 typename ByteAT = std::allocator< ByteT >
568 >
570  public basic_zip_istreambase< Elem, Tr, ElemA, ByteT, ByteAT >,
571  public std::basic_istream< Elem, Tr >
572 {
573 
574 public:
575 
577  typedef std::basic_istream< Elem, Tr > istream_type;
578  typedef std::basic_istream< Elem, Tr > & istream_reference;
579  typedef Elem char_type;
580  typedef unsigned char byte_type;
581 
585 
586  /// @brief Construct a unzipper stream
587  ///
588  /// @param istream_ input buffer
589  /// @param window_size_
590  /// @param read_buffer_size_
591  /// @param input_buffer_size_
593  istream_reference istream_,
594  size_t window_size_ = 15,
595  size_t read_buffer_size_ = default_buffer_size,
596  size_t input_buffer_size_ = default_buffer_size
597  ) :
598  zip_istreambase_type( istream_, window_size_, read_buffer_size_, input_buffer_size_ ),
599  istream_type( rdbuf() ),
600  m_is_gzip( false ),
601  m_gzip_crc( 0 ),
602  m_gzip_data_size( 0 )
603  {
604  if ( rdbuf()->get_zerr() == Z_OK ) check_header();
605  }
606 
607  /// @brief returns true if it is a gzip file
608  bool is_gzip() const { return m_is_gzip; }
609 
610  /// @brief reads the gzip footer
611  void read_footer();
612 
613  /// @brief return crc check result
614  ///
615  /// @note When you have finished reading the compressed data,
616  /// call read_footer to read the uncompressed data crc.
617  /// @note This method compares it to the crc of the uncompressed data.
618  ///
619  /// @return true if crc check is succesful
620  bool check_crc() const { return get_crc() == m_gzip_crc; }
621 
622  /// @brief return data size check
623  bool check_data_size() const { return get_out_size() == m_gzip_data_size; }
624 
625  /// @brief return the crc value in the file
626  uLong get_gzip_crc() const { return m_gzip_crc; }
627 
628  /// @brief return the data size in the file
629  uLong get_gzip_data_size() const { return m_gzip_data_size; }
630 
631 protected:
632 
633  static void read_uint32( istream_reference in_, unsigned long & x_ );
634 
635  int check_header();
636 
637  bool m_is_gzip;
638  uLong m_gzip_crc;
640 
641 }; // basic_zip_istream
642 
643 
644 // Types
649 
650 
651 } // namespace zlib_stream
652 
653 
654 // Implementation
655 #include <utility/io/zipstream.ipp>
656 
657 
658 #endif // INCLUDED_utility_io_zipstream_HPP
uLong get_crc() const
returns the uncompressed data crc
Definition: zipstream.hpp:346
basic_zip_ostream & write(char const *str, std::streamsize const count)
write a string
Definition: zipstream.hpp:506
std::basic_ostream< Elem, Tr > & ostream_reference
Definition: zipstream.hpp:258
basic_zip_streambuf< Elem, Tr, ElemA, ByteT, ByteAT > zip_streambuf_type
Definition: zipstream.hpp:265
uLong get_crc() const
returns the crc of the input data compressed so far
Definition: zipstream.hpp:138
std::basic_ostream< Elem, Tr > & ostream_reference
Definition: zipstream.hpp:401
std::streamsize flush_finalize()
flushes the zip buffer and output buffer and finalize the zip stream
Definition: zipstream.ipp:314
basic_zip_ostream< char > zip_ostream
Definition: zipstream.hpp:645
basic_zip_istreambase< Elem, Tr, ElemA, ByteT, ByteAT > zip_istreambase_type
Definition: zipstream.hpp:576
uLong get_in_size() const
returns the compressed data size
Definition: zipstream.hpp:352
std::basic_istream< Elem, Tr > istream_type
Definition: zipstream.hpp:577
basic_zip_ostream< Elem, Tr > & zflush()
flush inner buffer and zipper buffer
Definition: zipstream.hpp:455
ostream_reference get_ostream() const
returns a reference to the output stream
Definition: zipstream.hpp:132
uLong get_gzip_data_size() const
return the data size in the file
Definition: zipstream.hpp:629
std::streamsize unzip_from_stream(char_type *, std::streamsize)
Definition: zipstream.ipp:451
std::basic_streambuf< Elem, Tr > basic_streambuf_type
Definition: zipstream.hpp:87
uLong get_out_size() const
returns the number of uncompressed bytes
Definition: zipstream.hpp:220
basic_zip_ostream< Elem, Tr > & zflush_finalize()
flush inner and zipper buffers and finalize zip stream
Definition: zipstream.hpp:462
uLong get_in_size() const
returns the uncompressed data size
Definition: zipstream.hpp:295
std::basic_istream< Elem, Tr > & istream_reference
Definition: zipstream.hpp:180
basic_zip_ostream & put(char const c)
write char
Definition: zipstream.hpp:494
std::vector< byte_type, byte_allocator_type > byte_vector_type
Definition: zipstream.hpp:186
static void read_uint32(istream_reference in_, unsigned long &x_)
Definition: zipstream.ipp:618
basic_unzip_streambuf(istream_reference istream_, size_t window_size_, size_t read_buffer_size_, size_t input_buffer_size_)
Construct an unzip stream.
Definition: zipstream.ipp:348
static void put_long_as_uint32(ostream_reference out_, unsigned long x_)
Definition: zipstream.ipp:590
basic_zip_istreambase(istream_reference ostream_, size_t window_size_, size_t read_buffer_size_, size_t input_buffer_size_)
Definition: zipstream.hpp:328
bool is_gzip() const
returns true if it is a gzip
Definition: zipstream.hpp:451
bool zip_to_stream(char_type *, std::streamsize)
Definition: zipstream.ipp:170
uLong get_in_size() const
returns the size (bytes) of the input data compressed so far
Definition: zipstream.hpp:141
uLong get_out_size() const
returns the compressed data size
Definition: zipstream.hpp:292
std::streamsize flush()
flushes the zip buffer and output buffer
Definition: zipstream.ipp:300
Base class for unzip istreams.
Definition: zipstream.hpp:313
basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT > zip_ostreambase_type
Definition: zipstream.hpp:399
bool check_crc() const
return crc check result
Definition: zipstream.hpp:620
uLong get_crc() const
returns the uncompressed data crc
Definition: zipstream.hpp:289
A stream decorator that takes compressed input and unzips it to a istream.
Definition: zipstream.hpp:173
bool check_data_size() const
return data size check
Definition: zipstream.hpp:623
std::vector< char_type, char_allocator_type > char_vector_type
Definition: zipstream.hpp:187
uLong get_in_size() const
returns the number of read compressed bytes
Definition: zipstream.hpp:223
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.
Definition: zipstream.hpp:269
uLong get_crc() const
returns the crc of the uncompressed data so far
Definition: zipstream.hpp:217
int get_zerr() const
returns the zlib error state
Definition: zipstream.hpp:343
zip_streambuf_type * rdbuf()
returns the underlying zip ostream object
Definition: zipstream.hpp:283
basic_unzip_streambuf< Elem, Tr, ElemA, ByteT, ByteAT > unzip_streambuf_type
Definition: zipstream.hpp:326
std::basic_istream< Elem, Tr > & istream_reference
Definition: zipstream.hpp:578
istream_reference get_istream()
returns the compressed input istream
Definition: zipstream.hpp:208
byte_vector_type m_output_buffer
Definition: zipstream.hpp:157
std::basic_ostream< Elem, Tr > & ostream_reference
Definition: zipstream.hpp:88
uLong get_gzip_crc() const
return the crc value in the file
Definition: zipstream.hpp:626
basic_zip_istream< wchar_t > zip_wistream
Definition: zipstream.hpp:648
z_stream & get_zip_stream()
returns the zlib stream structure
Definition: zipstream.hpp:211
unzip_streambuf_type * rdbuf()
returns the underlying unzip istream object
Definition: zipstream.hpp:340
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.
Definition: zipstream.ipp:72
int get_zerr() const
returns the latest zlib error status
Definition: zipstream.hpp:135
std::basic_streambuf< Elem, Tr > basic_streambuf_type
Definition: zipstream.hpp:179
void reset_state()
resets the zip stream and zeros the crc
Definition: zipstream.ipp:328
std::vector< char_type, char_allocator_type > char_vector_type
Definition: zipstream.hpp:95
std::basic_istream< Elem, Tr > & istream_reference
Definition: zipstream.hpp:319
bool reset_zip_stream()
if end of stream, reset the zip stream and add header
Definition: zipstream.hpp:518
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.
Definition: zipstream.hpp:418
basic_zip_ostream< wchar_t > zip_wostream
Definition: zipstream.hpp:646
bool is_gzip() const
returns true if it is a gzip file
Definition: zipstream.hpp:608
const size_t default_buffer_size
Default gzip buffer size, change this to suite your needs.
Definition: zipstream.hpp:60
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.
Definition: zipstream.hpp:592
void init()
set global 'init_was_called' to true
Definition: init.cc:26
std::vector< byte_type, byte_allocator_type > byte_vector_type
Definition: zipstream.hpp:94
bool m_zip_stream_finalized
tracks to see if zip stream was finalized
Definition: zipstream.hpp:539
Base class for zip ostreams.
Definition: zipstream.hpp:252
EStrategy
Compression strategy, see zlib doc.
Definition: zipstream.hpp:64
basic_zip_ostream & operator<<(T const &t)
stream output
Definition: zipstream.hpp:482
A stream decorator that takes raw input and zips it to a ostream.
Definition: zipstream.hpp:81
int get_zerr() const
returns the latest zlib error state
Definition: zipstream.hpp:214
std::basic_ostream< Elem, Tr > ostream_type
Definition: zipstream.hpp:400
int get_zerr() const
returns the zlib error state
Definition: zipstream.hpp:286
uLong get_out_size() const
returns the size (bytes) of the compressed data so far
Definition: zipstream.hpp:144
void read_footer()
reads the gzip footer
Definition: zipstream.ipp:575
basic_zip_istream< char > zip_istream
Definition: zipstream.hpp:647
Altered zipstream library implementation.
uLong get_out_size() const
returns the uncompressed data size
Definition: zipstream.hpp:349
int_type overflow(int_type c)
Definition: zipstream.ipp:144