]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/zipios++/deflateoutputstreambuf.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / zipios++ / deflateoutputstreambuf.h
1 #ifndef DEFLATEOUTPUTSTREAMBUF_H
2 #define DEFLATEOUTPUTSTREAMBUF_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include "zipios++/meta-iostreams.h"
7 #include <vector>
8
9 #include <zlib.h>
10
11 #include "zipios++/filteroutputstreambuf.h"
12 #include "zipios++/ziphead.h"
13 #include "zipios++/zipios_defs.h"
14
15 namespace zipios {
16
17 using std::vector ;
18
19 /** DeflateOutputStreambuf is an output stream filter, that deflates
20     the data that is written to it before it passes it on to the
21     output stream it is attached to. Deflation/Inflation is a
22     compression/decompression method used in gzip and zip. The zlib
23     library is used to perform the actual deflation, this class only
24     wraps the functionality in an output stream filter. */
25 class DeflateOutputStreambuf : public FilterOutputStreambuf {
26 public:
27
28   /** DeflateOutputStreambuf constructor.
29       @param outbuf the streambuf to use for output.
30       @param user_init If false user must invoke init() before writing any data. 
31       (ZipOutputStreambuf needs to do this)
32       @param del_outbuf if true is specified outbuf will be deleted, when 
33       the DeflateOutputStreambuf is destructed. */
34   explicit DeflateOutputStreambuf( streambuf *outbuf, bool user_init = false, 
35                                    bool del_outbuf = false ) ;
36
37   /** Destructor. */
38   virtual ~DeflateOutputStreambuf() ;
39
40   bool init( int comp_level = 6 ) ;
41   bool closeStream() ;
42   
43   /** Returns the CRC32 for the current stream. The returned value is
44       the CRC for the data that has been compressed already (due to a
45       call to overflow()). As DeflateOutputStreambuf may buffer an
46       arbitrary amount of bytes until closeStream() has been invoked,
47       the returned value is not very useful before closeStream() has
48       been called. */
49   uint32 getCrc32() const         { return _crc32 ;           }
50
51   /** Returns the number of bytes written to the streambuf, that has
52       been processed from the input buffer by the compressor. After
53       closeStream() has been called this number is the total number of
54       bytes written to the stream. */
55   uint32 getCount() const         { return _overflown_bytes ; } 
56
57 protected:
58   virtual int overflow( int c = EOF ) ;
59   virtual int sync() ;
60
61   /** Flushes _outvec and updates _zs.next_out and _zs.avail_out. */
62   bool flushOutvec() ;
63
64   /** Flushes the remaining data in the zlib buffers, after which the
65       only possible operations are deflateEnd() or deflateReset(). */
66   void endDeflation() ;
67
68 private:
69   z_stream _zs ;
70   bool _zs_initialized ;
71 protected: // FIXME: reconsider design?
72   const int _invecsize ;
73   vector< char > _invec ;
74   const int _outvecsize ;
75   vector< char > _outvec ;
76
77   uint32 _crc32 ;
78   uint32 _overflown_bytes ;
79 };
80
81
82 } // namespace
83
84
85
86 #endif
87
88 /** \file
89     Header file that defines DeflateOutputStreambuf.
90 */
91
92 /*
93   Zipios++ - a small C++ library that provides easy access to .zip files.
94   Copyright (C) 2000  Thomas Søndergaard
95   
96   This library is free software; you can redistribute it and/or
97   modify it under the terms of the GNU Lesser General Public
98   License as published by the Free Software Foundation; either
99   version 2 of the License, or (at your option) any later version.
100   
101   This library is distributed in the hope that it will be useful,
102   but WITHOUT ANY WARRANTY; without even the implied warranty of
103   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
104   Lesser General Public License for more details.
105   
106   You should have received a copy of the GNU Lesser General Public
107   License along with this library; if not, write to the Free Software
108   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
109 */