zipios++  2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
deflateoutputstreambuf.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef DEFLATEOUTPUTSTREAMBUF_HPP
3 #define DEFLATEOUTPUTSTREAMBUF_HPP
4 
5 /*
6  Zipios++ - a small C++ library that provides easy access to .zip files.
7 
8  Copyright (C) 2000-2007 Thomas Sondergaard
9  Copyright (C) 2015 Made to Order Software Corporation
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 2 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 
36 
37 #include "zipios++/fileentry.hpp"
38 
39 #include <cstdint>
40 
41 #include <zlib.h>
42 
43 
44 namespace zipios
45 {
46 
48 {
49 public:
50  DeflateOutputStreambuf(std::streambuf * outbuf);
51  DeflateOutputStreambuf(DeflateOutputStreambuf const & src) = delete;
53  virtual ~DeflateOutputStreambuf();
54 
55  bool init(FileEntry::CompressionLevel compression_level);
56  void closeStream();
57  uint32_t getCrc32() const;
58  size_t getSize() const;
59 
60 protected:
61  virtual int overflow(int c = EOF);
62  virtual int sync();
63 
64  uint32_t m_overflown_bytes = 0;
65  std::vector<char> m_invec;
66 
67 private:
68  void endDeflation();
69  void flushOutvec();
70 
71  z_stream m_zs;
72  bool m_zs_initialized = false;
73 
74  std::vector<char> m_outvec;
75 
76  uint32_t m_crc32 = 0;
77 };
78 
79 
80 } // zipios namespace
81 
82 // Local Variables:
83 // mode: cpp
84 // indent-tabs-mode: nil
85 // c-basic-offset: 4
86 // tab-width: 4
87 // End:
88 
89 // vim: ts=4 sw=4 et
90 #endif
A base class to develop output stream filters.
virtual int overflow(int c=EOF)
Handle an overflow.
void closeStream()
Closing the stream.
void endDeflation()
End deflation of current file.
virtual int sync()
Synchronize the buffer.
bool init(FileEntry::CompressionLevel compression_level)
Initialize the zlib library.
int CompressionLevel
The compression level to be used to save an entry.
Definition: fileentry.hpp:85
void flushOutvec()
Flush the cached output data.
DeflateOutputStreambuf(std::streambuf *outbuf)
Initialize a DeflateOutputStreambuf object.
virtual ~DeflateOutputStreambuf()
Clean up any resources used by this object.
Define the zipios::FileEntry class.
Declarations of the zipios::FilterOutputStreambuf.
size_t getSize() const
Retrieve the size of the file deflated.
uint32_t getCrc32() const
Get the CRC32 of the file.
A class to handle stream deflate on the fly.
DeflateOutputStreambuf & operator=(DeflateOutputStreambuf const &rhs)=delete