zipios++
2.0.2
Zipios++ – a small C++ library that provides 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. More... | |
ZipOutputStreambuf (ZipOutputStreambuf const &src)=delete | |
virtual | ~ZipOutputStreambuf () |
Clean up the buffer. More... | |
void | close () |
Close the output stream buffer. More... | |
void | closeEntry () |
Close this buffer entry. More... | |
void | closeStream () |
Closing the stream. More... | |
void | finish () |
Finish up an output stream buffer. More... | |
uint32_t | getCrc32 () const |
Get the CRC32 of the file. More... | |
size_t | getSize () const |
Retrieve the size of the file deflated. More... | |
bool | init (FileEntry::CompressionLevel compression_level) |
Initialize the zlib library. More... | |
ZipOutputStreambuf & | operator= (ZipOutputStreambuf const &rhs)=delete |
void | putNextEntry (FileEntry::pointer_t entry) |
Start saving an entry in the output buffer. More... | |
void | setComment (std::string const &comment) |
Set the archive comment. More... | |
Protected Member Functions | |
virtual int | overflow (int c=EOF) override |
Implementation of the overflow() function. More... | |
virtual int | sync () override |
Implement the sync() functionality. More... | |
Protected Attributes | |
std::vector< char > | m_invec |
std::streambuf * | m_outbuf |
uint32_t | m_overflown_bytes = 0 |
Private Member Functions | |
void | setEntryClosedState () |
Mark the current entry as closed. More... | |
void | updateEntryHeaderInfo () |
Save the header information. More... | |
Private Attributes | |
FileEntry::CompressionLevel | m_compression_level |
FileEntry::vector_t | m_entries |
bool | m_open = true |
bool | m_open_entry = false |
std::string | m_zip_comment |
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 92 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 113 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 160 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 131 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 205 of file deflateoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::m_zs, and zipios::DeflateOutputStreambuf::m_zs_initialized.
Referenced by closeEntry(), zipios::GZIPOutputStreambuf::finish(), and zipios::DeflateOutputStreambuf::~DeflateOutputStreambuf().
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 173 of file zipoutputstreambuf.cpp.
References closeEntry(), m_entries, m_open, zipios::FilterOutputStreambuf::m_outbuf, m_zip_comment, and zipios::anonymous_namespace{zipoutputstreambuf.cpp}::writeZipCentralDirectory().
Referenced by close(), and ~ZipOutputStreambuf().
|
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 239 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 256 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.
Definition at line 106 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.
[in] | c | The character that made it all happen. Maybe EOF. |
Reimplemented from zipios::DeflateOutputStreambuf.
Definition at line 273 of file zipoutputstreambuf.cpp.
References zipios::FileEntry::COMPRESSION_LEVEL_NONE, zipios::getBufferSize(), m_compression_level, 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 197 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 253 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 331 of file zipoutputstreambuf.cpp.
References 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 318 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 353 of file zipoutputstreambuf.cpp.
References zipios::DeflateOutputStreambuf::getCrc32(), zipios::ZipLocalEntry::getHeaderSize(), zipios::DeflateOutputStreambuf::getSize(), m_entries, m_open_entry, zipios::FilterOutputStreambuf::m_outbuf, and zipios::ZipLocalEntry::write().
Referenced by closeEntry().
|
private |
Definition at line 65 of file zipoutputstreambuf.hpp.
Referenced by closeEntry(), overflow(), and putNextEntry().
|
private |
Definition at line 64 of file zipoutputstreambuf.hpp.
Referenced by finish(), putNextEntry(), and updateEntryHeaderInfo().
|
protectedinherited |
Definition at line 65 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::init(), overflow(), zipios::DeflateOutputStreambuf::overflow(), and putNextEntry().
|
private |
Definition at line 67 of file zipoutputstreambuf.hpp.
Referenced by finish().
|
private |
Definition at line 66 of file zipoutputstreambuf.hpp.
Referenced by closeEntry(), putNextEntry(), setEntryClosedState(), and updateEntryHeaderInfo().
|
protectedinherited |
Definition at line 49 of file filteroutputstreambuf.hpp.
Referenced by zipios::FilterOutputStreambuf::FilterOutputStreambuf(), finish(), zipios::DeflateOutputStreambuf::flushOutvec(), overflow(), putNextEntry(), updateEntryHeaderInfo(), zipios::GZIPOutputStreambuf::writeHeader(), and zipios::GZIPOutputStreambuf::writeInt().
|
protectedinherited |
Definition at line 64 of file deflateoutputstreambuf.hpp.
Referenced by zipios::DeflateOutputStreambuf::endDeflation(), zipios::DeflateOutputStreambuf::getSize(), overflow(), and putNextEntry().
|
private |
Definition at line 63 of file zipoutputstreambuf.hpp.
Referenced by finish(), and setComment().