zipios++  2.0.2 Zipios++ – a small C++ library that provides easy access to .zip files.
zipios::ZipEndOfCentralDirectory Class Reference

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

Detailed Description

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.

Constructor & Destructor Documentation

 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.

Parameters
 [in] zip_comment The global comment of a Zip archive.

Definition at line 82 of file zipendofcentraldirectory.cpp.

Member Function Documentation

 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.)

Returns
The size, in bytes, of the Central Directory.
setCentralDirectorySize()

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.

Returns
The total number of entries archived in this Zip file.
setCount()

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.

Warning
There is getOffsetFromEnd() which returns the offset of the ZipEndOfCentralDirectory itself and not the Central Directory.
Returns
The offset in the Zip archive of the Central Directory.
getOffsetFromEnd()
setOffset()

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).

Note
If a read from the buffer fails, then an exception is raised. Since we are reading from a buffer, it should not happen except if the ZipEndOfCentralDirectory indicates that there is a comment and the comment is not there or some characters are missing.
Exceptions
 FileCollectionException This exception is raised if the number of entries is not equal to the total number of entries, as expected.
Parameters
 [in] buf The buffer with the file data. [in] pos The position at which we are expected to check.
Returns
true if the ZipEndOfCentralDirectory was found, false otherwise.

Definition at line 228 of file zipendofcentraldirectory.cpp.

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.

Parameters
 [in] size The size of the Central Directory.
getCentralDirectorySize()

Definition at line 160 of file zipendofcentraldirectory.cpp.

References m_central_directory_size.

 void zipios::ZipEndOfCentralDirectory::setCount ( size_t count )

This function is used to define the number of entries one will find in the central directory.

Note
The maximum number of entries is 65535. (until we add support for 64 bit Zip archives.)
Parameters
 [in] count The number of entries in the Central Directory.
getCount()

Definition at line 179 of file zipendofcentraldirectory.cpp.

References m_central_directory_entries.

 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.

Note
Only the offset of the Central Directory can be changed by this function.
Parameters
 [in] start_offset The start offset of the Central Directory.
getOffset();

Definition at line 200 of file zipendofcentraldirectory.cpp.

References m_central_directory_offset.

 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.

Note
If the output pointer is not valid, the function will throw via the various zipWrite() it uses.
The function does not change the output pointer of the stream before writing to it.
Exceptions
 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.)
Parameters
 [in] os The output stream where the data is to be saved.
Todo:
Add support for 64 bit Zip archive. This would allow for pretty much all the following conditions to be dropped out.

Definition at line 307 of file zipendofcentraldirectory.cpp.

Member Data Documentation

 size_t zipios::ZipEndOfCentralDirectory::m_central_directory_entries = 0
private

Definition at line 62 of file zipendofcentraldirectory.hpp.

Referenced by getCount(), read(), setCount(), and write().

 offset_t zipios::ZipEndOfCentralDirectory::m_central_directory_offset = 0
private

Definition at line 64 of file zipendofcentraldirectory.hpp.

Referenced by getOffset(), read(), setOffset(), and write().

 size_t zipios::ZipEndOfCentralDirectory::m_central_directory_size = 0
private
 std::string zipios::ZipEndOfCentralDirectory::m_zip_comment
private

Definition at line 65 of file zipendofcentraldirectory.hpp.

Referenced by read(), and write().

The documentation for this class was generated from the following files: