zipios 2.3.4
Zipios -- a small C++ library providing 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-2022 Made to Order Software Corp. All Rights Reserved
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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
36
37#include "zipios/fileentry.hpp"
38
39#include <cstdint>
40
41#include <zlib.h>
42
43
44namespace zipios
45{
46
48{
49public:
50 DeflateOutputStreambuf(std::streambuf * outbuf);
53
55
56 bool init(FileEntry::CompressionLevel compression_level);
57 void closeStream();
58 uint32_t getCrc32() const;
59 size_t getSize() const;
60
61protected:
62 virtual int overflow(int c = EOF);
63 virtual int sync();
64
65 uint32_t m_overflown_bytes = 0;
66 std::vector<char> m_invec = std::vector<char>();
67 uint32_t m_crc32 = 0;
68
69private:
70 void endDeflation();
71 void flushOutvec();
72
73 z_stream m_zs = z_stream();
74 bool m_zs_initialized = false;
75
76 std::vector<char> m_outvec = std::vector<char>();
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 class to handle stream deflate on the fly.
virtual ~DeflateOutputStreambuf()
Clean up any resources used by this object.
bool init(FileEntry::CompressionLevel compression_level)
Initialize the zlib library.
uint32_t getCrc32() const
Get the CRC32 of the file.
void endDeflation()
End deflation of current file.
void flushOutvec()
Flush the cached output data.
virtual int sync()
Synchronize the buffer.
virtual int overflow(int c=EOF)
Handle an overflow.
DeflateOutputStreambuf & operator=(DeflateOutputStreambuf const &rhs)=delete
DeflateOutputStreambuf(DeflateOutputStreambuf const &rhs)=delete
size_t getSize() const
Retrieve the size of the file deflated.
int CompressionLevel
The compression level to be used to save an entry.
Definition fileentry.hpp:85
A base class to develop output stream filters.
Define the zipios::FileEntry class.
Declarations of the zipios::FilterOutputStreambuf.
The zipios namespace includes the Zipios library definitions.