zipios 2.3.4
Zipios -- a small C++ library providing easy access to .zip files.
|
Handle the output buffer of a zip archive. More...
#include <zipoutputstreambuf.hpp>
Public Member Functions | |
ZipOutputStreambuf (std::streambuf *outbuf) | |
Initialize a ZipOutputStreambuf object. | |
ZipOutputStreambuf (ZipOutputStreambuf const &rhs)=delete | |
virtual | ~ZipOutputStreambuf () |
Clean up the buffer. | |
void | close () |
Close the output stream buffer. | |
void | closeEntry () |
Close this buffer entry. | |
void | closeStream () |
Closing the stream. | |
void | finish () |
Finish up an output stream buffer. | |
uint32_t | getCrc32 () const |
Get the CRC32 of the file. | |
size_t | getSize () const |
Retrieve the size of the file deflated. | |
bool | init (FileEntry::CompressionLevel compression_level) |
Initialize the zlib library. | |
ZipOutputStreambuf & | operator= (ZipOutputStreambuf const &rhs)=delete |
void | putNextEntry (FileEntry::pointer_t entry) |
Start saving an entry in the output buffer. | |
void | setComment (std::string const &comment) |
Set the archive comment. | |
Protected Member Functions | |
virtual int | overflow (int c=EOF) override |
Implementation of the overflow() function. | |
virtual int | sync () override |
Implement the sync() functionality. | |
Protected Attributes | |
uint32_t | m_crc32 = 0 |
std::vector< char > | m_invec = std::vector<char>() |
std::streambuf * | m_outbuf = nullptr |
uint32_t | m_overflown_bytes = 0 |
Private Member Functions | |
void | endDeflation () |
End deflation of current file. | |
void | flushOutvec () |
Flush the cached output data. | |
void | setEntryClosedState () |
Mark the current entry as closed. | |
void | updateEntryHeaderInfo () |
Save the header information. | |
Private Attributes | |
FileEntry::CompressionLevel | m_compression_level = FileEntry::COMPRESSION_LEVEL_DEFAULT |
FileEntry::vector_t | m_entries = FileEntry::vector_t() |
bool | m_open = true |
bool | m_open_entry = false |
std::vector< char > | m_outvec = std::vector<char>() |
std::string | m_zip_comment = std::string() |
z_stream | m_zs = z_stream() |
bool | m_zs_initialized = false |
The ZipOutputStreambuf class is a zip archive output streambuf filter.
Definition at line 41 of file zipoutputstreambuf.hpp.
zipios::ZipOutputStreambuf::ZipOutputStreambuf | ( | std::streambuf * | outbuf | ) |
Note that a new initialized ZipOutputStreambuf is not ready to accept data, putNextEntry() must be invoked at least once first.
[in] | outbuf | The streambuf to use for output. |
Definition at line 95 of file zipoutputstreambuf.cpp.
|
delete |
|
virtual |
This function cleans up this output buffer. In general this ensures that the data still cached gets flushed.
Definition at line 114 of file zipoutputstreambuf.cpp.
References finish().
void zipios::ZipOutputStreambuf::close | ( | ) |
This function calls finish to make sure that any cached data is saved and then close the stream buffer.
Definition at line 161 of file zipoutputstreambuf.cpp.
References finish().
void zipios::ZipOutputStreambuf::closeEntry | ( | ) |
Closes the current output buffer entry and positions the stream write pointer at the beginning of the next entry.
Definition at line 132 of file zipoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::closeStream(), zipios::FileEntry::COMPRESSION_LEVEL_NONE, m_compression_level, m_open_entry, overflow(), setEntryClosedState(), and updateEntryHeaderInfo().
Referenced by finish(), and putNextEntry().
|
inherited |
This function is expected to be called once the stream is getting closed (the buffer is destroyed.)
It ensures that the zlib library last few bytes get flushed and then mark the class as closed.
Note that this function can be called to close the current zlib library stream and start a new one. It is actually called from the putNextEntry() function (via the closeEntry() function.)
Definition at line 200 of file deflateoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::m_zs, and zipios::DeflateOutputStreambuf::m_zs_initialized.
Referenced by zipios::DeflateOutputStreambuf::~DeflateOutputStreambuf(), closeEntry(), and zipios::GZIPOutputStreambuf::finish().
|
privateinherited |
This function flushes the remaining data in the zlib buffers, after which the only possible operations are deflateEnd() or deflateReset().
Definition at line 377 of file deflateoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::flushOutvec(), zipios::getBufferSize(), zipios::DeflateOutputStreambuf::m_outvec, zipios::DeflateOutputStreambuf::m_overflown_bytes, zipios::DeflateOutputStreambuf::m_zs, and zipios::DeflateOutputStreambuf::overflow().
Referenced by zipios::DeflateOutputStreambuf::closeStream().
void zipios::ZipOutputStreambuf::finish | ( | ) |
Closes the current entry (if one is open), then writes the Zip Central Directory Structure closing the ZipOutputStream. The output stream (std::ostream) that the zip archive is being written to is not closed.
Definition at line 174 of file zipoutputstreambuf.cpp.
References closeEntry(), m_entries, m_open, zipios::FilterOutputStreambuf::m_outbuf, and m_zip_comment.
Referenced by ~ZipOutputStreambuf(), and close().
|
privateinherited |
This function flushes m_outvec and updates the output pointer and size m_zs.next_out and m_zs.avail_out.
Definition at line 346 of file deflateoutputstreambuf.cpp.
References zipios::getBufferSize(), zipios::FilterOutputStreambuf::m_outbuf, zipios::DeflateOutputStreambuf::m_outvec, and zipios::DeflateOutputStreambuf::m_zs.
Referenced by zipios::DeflateOutputStreambuf::endDeflation(), and zipios::DeflateOutputStreambuf::overflow().
|
inherited |
This function returns the CRC32 for the current file.
The returned value is the CRC for the data that has been compressed already (due to calls to overflow()). As DeflateOutputStreambuf may buffer an arbitrary amount of bytes until closeStream() has been invoked, the returned value is not very useful before closeStream() has been called.
Definition at line 234 of file deflateoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::m_crc32.
Referenced by updateEntryHeaderInfo(), and zipios::GZIPOutputStreambuf::writeTrailer().
|
inherited |
This function returns the number of bytes written to the streambuf object and that were processed from the input buffer by the compressor. After closeStream() has been called this number is the total number of bytes written to the stream. In other words, the size of the uncompressed data.
Definition at line 251 of file deflateoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::m_overflown_bytes.
Referenced by updateEntryHeaderInfo(), and zipios::GZIPOutputStreambuf::writeTrailer().
|
inherited |
This method is called in the constructor, so it must not write anything to the output streambuf m_outbuf (see notice in constructor.)
It will initialize the output stream as required to accept data to be compressed using the zlib library. The compression level is expected to come from the FileEntry which is about to be saved in the file.
[in] | compression_level | The level of compression. A number from 1 to 100 or a special number representing the best, minimum, maximum compression available. |
Definition at line 101 of file deflateoutputstreambuf.cpp.
References zipios::FileEntry::COMPRESSION_LEVEL_DEFAULT, zipios::FileEntry::COMPRESSION_LEVEL_FASTEST, zipios::FileEntry::COMPRESSION_LEVEL_MAXIMUM, zipios::FileEntry::COMPRESSION_LEVEL_MINIMUM, zipios::FileEntry::COMPRESSION_LEVEL_NONE, zipios::FileEntry::COMPRESSION_LEVEL_SMALLEST, zipios::getBufferSize(), zipios::DeflateOutputStreambuf::m_crc32, zipios::DeflateOutputStreambuf::m_invec, zipios::DeflateOutputStreambuf::m_outvec, zipios::DeflateOutputStreambuf::m_zs, and zipios::DeflateOutputStreambuf::m_zs_initialized.
Referenced by zipios::GZIPOutputStreambuf::GZIPOutputStreambuf(), and putNextEntry().
|
delete |
|
overrideprotectedvirtual |
When writing to a buffer, the overflow() function gets called when there is no more room in the output buffer. The buffer is expected to flush the data to disk and reset the buffer availability.
IOException | This function generates an exception if saving the data to the output fails. |
[in] | c | The character that made it all happen. Maybe EOF. |
Reimplemented from zipios::DeflateOutputStreambuf.
Definition at line 278 of file zipoutputstreambuf.cpp.
References zipios::FileEntry::COMPRESSION_LEVEL_NONE, zipios::getBufferSize(), m_compression_level, zipios::DeflateOutputStreambuf::m_crc32, zipios::DeflateOutputStreambuf::m_invec, zipios::FilterOutputStreambuf::m_outbuf, zipios::DeflateOutputStreambuf::m_overflown_bytes, and zipios::DeflateOutputStreambuf::overflow().
Referenced by closeEntry().
void zipios::ZipOutputStreambuf::putNextEntry | ( | FileEntry::pointer_t | entry | ) |
Opens the next entry in the zip archive and returns a const pointer to a FileEntry object for the entry.
If a previous entry was still open, the function calls closeEntry() first.
[in] | entry | The entry to be saved and made current. |
Definition at line 198 of file zipoutputstreambuf.cpp.
References closeEntry(), zipios::FileEntry::COMPRESSION_LEVEL_NONE, zipios::getBufferSize(), zipios::DeflateOutputStreambuf::init(), m_compression_level, m_entries, zipios::DeflateOutputStreambuf::m_invec, m_open_entry, zipios::FilterOutputStreambuf::m_outbuf, zipios::DeflateOutputStreambuf::m_overflown_bytes, zipios::STORED, and zipios::ZipLocalEntry::write().
void zipios::ZipOutputStreambuf::setComment | ( | std::string const & | comment | ) |
This function saves a global comment for the Zip archive.
You may set it to an empty string which means that no comment will be saved.
The comment is saved when the first entry is saved so it has to be put in there early on.
[in] | comment | The comment to save in the Zip archive. |
Definition at line 254 of file zipoutputstreambuf.cpp.
References m_zip_comment.
|
private |
After the putNextEntry() call and saving of the file content, the closeEntry() function can be called to close the entry. The entry is really closed when this setEntryClosedState() is called.
Definition at line 337 of file zipoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::m_crc32, and m_open_entry.
Referenced by closeEntry().
|
overrideprotectedvirtual |
This virtual function is reimplemented to make sure that the system does not run a default sync() function.
This function calls the DeflateOutputStreambuf::sync() function which returns -1 because it will not "synchronize" the input buffer.
Reimplemented from zipios::DeflateOutputStreambuf.
Definition at line 324 of file zipoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::sync().
|
private |
This function saves parameters that are now available in the header of the local entry.
These parameters include:
Definition at line 360 of file zipoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::getCrc32(), zipios::DeflateOutputStreambuf::getSize(), m_entries, m_open_entry, zipios::FilterOutputStreambuf::m_outbuf, and zipios::ZipLocalEntry::write().
Referenced by closeEntry().
|
private |
Definition at line 66 of file zipoutputstreambuf.hpp.
Referenced by closeEntry(), overflow(), and putNextEntry().
|
protectedinherited |
Definition at line 67 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::getCrc32(), zipios::DeflateOutputStreambuf::init(), zipios::DeflateOutputStreambuf::overflow(), overflow(), and setEntryClosedState().
|
private |
Definition at line 65 of file zipoutputstreambuf.hpp.
Referenced by finish(), putNextEntry(), and updateEntryHeaderInfo().
|
protectedinherited |
Definition at line 66 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::init(), zipios::DeflateOutputStreambuf::overflow(), overflow(), and putNextEntry().
|
private |
Definition at line 68 of file zipoutputstreambuf.hpp.
Referenced by finish().
|
private |
Definition at line 67 of file zipoutputstreambuf.hpp.
Referenced by closeEntry(), putNextEntry(), setEntryClosedState(), and updateEntryHeaderInfo().
|
protectedinherited |
Definition at line 50 of file filteroutputstreambuf.hpp.
Referenced by zipios::FilterOutputStreambuf::FilterOutputStreambuf(), finish(), zipios::DeflateOutputStreambuf::flushOutvec(), overflow(), putNextEntry(), updateEntryHeaderInfo(), zipios::GZIPOutputStreambuf::writeHeader(), and zipios::GZIPOutputStreambuf::writeInt().
|
privateinherited |
Definition at line 76 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::flushOutvec(), zipios::DeflateOutputStreambuf::init(), and zipios::DeflateOutputStreambuf::overflow().
|
protectedinherited |
Definition at line 65 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::getSize(), overflow(), and putNextEntry().
|
private |
Definition at line 64 of file zipoutputstreambuf.hpp.
Referenced by finish(), and setComment().
|
privateinherited |
Definition at line 73 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::closeStream(), zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::flushOutvec(), zipios::DeflateOutputStreambuf::init(), and zipios::DeflateOutputStreambuf::overflow().
|
privateinherited |
Definition at line 74 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::closeStream(), and zipios::DeflateOutputStreambuf::init().