zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
Marker at the end of a Zip archive file. More...
#include <zipendofcentraldirectory.hpp>
Public Member Functions | |
ZipEndOfCentralDirectory (std::string const &zip_comment="") | |
Initialize an ZipEndOfCentralDirectory object. More... | |
size_t | getCentralDirectorySize () const |
Retrieve the size of the Central Directory in bytes. More... | |
size_t | getCount () const |
Retrieve the number of entries. More... | |
offset_t | getOffset () const |
Retrieve the offset of the Central Directory. More... | |
bool | read (::zipios::buffer_t const &buf, size_t pos) |
Attempt to read an ZipEndOfCentralDirectory structure. More... | |
void | setCentralDirectorySize (size_t size) |
Define the size of the central directory. More... | |
void | setCount (size_t c) |
Set the number of entries. More... | |
void | setOffset (offset_t new_offset) |
Offset of the Central Directory. More... | |
void | write (std::ostream &os) |
Write the ZipEndOfCentralDirectory structure to a stream. More... | |
Private Attributes | |
size_t | m_central_directory_entries = 0 |
offset_t | m_central_directory_offset = 0 |
size_t | m_central_directory_size = 0 |
std::string | m_zip_comment |
This class is used to read and write the end of the Central Directory structure. In most cases, this structure is stored at the end of the zip archive file, and contains some global information about the file, including the position of the start of the Central Directory.
Definition at line 45 of file zipendofcentraldirectory.hpp.
zipios::ZipEndOfCentralDirectory::ZipEndOfCentralDirectory | ( | std::string const & | zip_comment = "" | ) |
This function initializes an ZipEndOfCentralDirectory object. By default, all the numbers are set to zero and the global Zip file comment is set to the empty string.
[in] | zip_comment | The global comment of a Zip archive. |
Definition at line 82 of file zipendofcentraldirectory.cpp.
size_t zipios::ZipEndOfCentralDirectory::getCentralDirectorySize | ( | ) | const |
This function returns the size of the Central Directory structure in the file. This size varies because each entry includes data that change in size (i.e. filename, comment, extra data.)
Definition at line 102 of file zipendofcentraldirectory.cpp.
References m_central_directory_size.
Referenced by zipios::ZipFile::ZipFile().
size_t zipios::ZipEndOfCentralDirectory::getCount | ( | ) | const |
This function returns the number of entries that will be found in the Central Directory.
Since Zipios++ has no support for split Zip archive files (i.e. one large archive written on multiple disks), the total number of entries, or the number of entries in this archive is always exactly the same.
Definition at line 121 of file zipendofcentraldirectory.cpp.
References m_central_directory_entries.
Referenced by zipios::ZipFile::ZipFile().
offset_t zipios::ZipEndOfCentralDirectory::getOffset | ( | ) | const |
This function is expected to be called after a call to read(). It includes the offset of the central directory, which in most cases appears before the ZipEndOfCentralDirectory block.
Definition at line 142 of file zipendofcentraldirectory.cpp.
References m_central_directory_offset.
Referenced by zipios::ZipFile::ZipFile().
bool zipios::ZipEndOfCentralDirectory::read | ( | ::zipios::buffer_t const & | buf, |
size_t | pos | ||
) |
This function tries to read an ZipEndOfCentralDirectory structure from the specified buffer. This function expects a BackBuffer, which is used because that is generally the fastest way to read the data (instead of scanning the entire file).
FileCollectionException | This exception is raised if the number of entries is not equal to the total number of entries, as expected. |
[in] | buf | The buffer with the file data. |
[in] | pos | The position at which we are expected to check. |
Definition at line 228 of file zipendofcentraldirectory.cpp.
References zipios::anonymous_namespace{zipendofcentraldirectory.cpp}::g_signature, m_central_directory_entries, m_central_directory_offset, m_central_directory_size, m_zip_comment, and zipios::zipRead().
Referenced by zipios::ZipFile::ZipFile().
void zipios::ZipEndOfCentralDirectory::setCentralDirectorySize | ( | size_t | size | ) |
When creating a Zip archive, it is necessary to call this function to define the size of the Central Directory block. This size cannot be inferred or calculated without wasting a lot of time re-reading the Central Directory, hence the function to avoid doing such.
[in] | size | The size of the Central Directory. |
Definition at line 160 of file zipendofcentraldirectory.cpp.
References m_central_directory_size.
Referenced by zipios::anonymous_namespace{zipoutputstreambuf.cpp}::writeZipCentralDirectory().
void zipios::ZipEndOfCentralDirectory::setCount | ( | size_t | count | ) |
This function is used to define the number of entries one will find in the central directory.
[in] | count | The number of entries in the Central Directory. |
Definition at line 179 of file zipendofcentraldirectory.cpp.
References m_central_directory_entries.
Referenced by zipios::anonymous_namespace{zipoutputstreambuf.cpp}::writeZipCentralDirectory().
void zipios::ZipEndOfCentralDirectory::setOffset | ( | offset_t | start_offset | ) |
This function defines the offset at which the Central Directory starts. Before writing the Central Directory, we expect the user to call tell() and save the value using this function. This is important when creating a Zip archive.
[in] | start_offset | The start offset of the Central Directory. |
Definition at line 200 of file zipendofcentraldirectory.cpp.
References m_central_directory_offset.
Referenced by zipios::anonymous_namespace{zipoutputstreambuf.cpp}::writeZipCentralDirectory().
void zipios::ZipEndOfCentralDirectory::write | ( | std::ostream & | os | ) |
This function writes the currently defined end of central directory to disk. This entry is expected to be written at the very end of a Zip archive file.
FileCollectionException | This function throws this exception if the data cannot be saved. In general this means there are too many entries, the size is too large or the comment is more than 64Kb (some of which will be resolved with Zip64 support.) |
[in] | os | The output stream where the data is to be saved. |
Definition at line 307 of file zipendofcentraldirectory.cpp.
References zipios::anonymous_namespace{zipendofcentraldirectory.cpp}::g_signature, m_central_directory_entries, m_central_directory_offset, m_central_directory_size, m_zip_comment, and zipios::zipWrite().
Referenced by zipios::anonymous_namespace{zipoutputstreambuf.cpp}::writeZipCentralDirectory().
|
private |
Definition at line 62 of file zipendofcentraldirectory.hpp.
Referenced by getCount(), read(), setCount(), and write().
|
private |
Definition at line 64 of file zipendofcentraldirectory.hpp.
Referenced by getOffset(), read(), setOffset(), and write().
|
private |
Definition at line 63 of file zipendofcentraldirectory.hpp.
Referenced by getCentralDirectorySize(), read(), setCentralDirectorySize(), and write().
|
private |
Definition at line 65 of file zipendofcentraldirectory.hpp.