1 #ifndef DEFLATEOUTPUTSTREAMBUF_H
2 #define DEFLATEOUTPUTSTREAMBUF_H
4 #include "zipios++/zipios-config.h"
6 #include "zipios++/meta-iostreams.h"
11 #include "zipios++/filteroutputstreambuf.h"
12 #include "zipios++/ziphead.h"
13 #include "zipios++/zipios_defs.h"
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 {
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 ) ;
38 virtual ~DeflateOutputStreambuf() ;
40 bool init( int comp_level = 6 ) ;
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
49 uint32 getCrc32() const { return _crc32 ; }
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 ; }
58 virtual int overflow( int c = EOF ) ;
61 /** Flushes _outvec and updates _zs.next_out and _zs.avail_out. */
64 /** Flushes the remaining data in the zlib buffers, after which the
65 only possible operations are deflateEnd() or deflateReset(). */
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 ;
78 uint32 _overflown_bytes ;
89 Header file that defines DeflateOutputStreambuf.
93 Zipios++ - a small C++ library that provides easy access to .zip files.
94 Copyright (C) 2000 Thomas Søndergaard
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.
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.
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