zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
A FileEntry represents an entry in a FileCollection. More...
#include <fileentry.hpp>
Public Types | |
typedef std::vector< unsigned char > | buffer_t |
typedef int | CompressionLevel |
The compression level to be used to save an entry. More... | |
typedef uint32_t | crc32_t |
typedef uint32_t | dostime_t |
typedef std::shared_ptr < FileEntry > | pointer_t |
typedef std::vector< pointer_t > | vector_t |
Public Member Functions | |
FileEntry (FilePath const &filename, std::string const &comment=std::string()) | |
Initialize a FileEntry object. More... | |
virtual | ~FileEntry () |
Clean up a FileEntry object. More... | |
virtual pointer_t | clone () const =0 |
Create a clone of a file entry. More... | |
virtual std::string | getComment () const |
Retrieve the comment of the file entry. More... | |
virtual size_t | getCompressedSize () const |
Retrive the size of the file when compressed. More... | |
virtual crc32_t | getCrc () const |
Return the CRC of the entry. More... | |
std::streampos | getEntryOffset () const |
Get the offset of this entry in a Zip archive. More... | |
virtual buffer_t | getExtra () const |
Some extra data to be stored along the entry. More... | |
virtual std::string | getFileName () const |
Return the basename of this entry. More... | |
virtual size_t | getHeaderSize () const |
Retrieve the size of the header. More... | |
virtual CompressionLevel | getLevel () const |
Retrieve the compression level. More... | |
virtual StorageMethod | getMethod () const |
Return the method used to create this entry. More... | |
virtual std::string | getName () const |
Return the filename of the entry. More... | |
virtual size_t | getSize () const |
Retrieve the size of the file when uncompressed. More... | |
virtual dostime_t | getTime () const |
Get the MS-DOS date/time of this entry. More... | |
virtual std::time_t | getUnixTime () const |
Get the Unix date/time of this entry. More... | |
bool | hasCrc () const |
Check whether the CRC32 was defined. More... | |
virtual bool | isDirectory () const |
Check whether the filename represents a directory. More... | |
virtual bool | isEqual (FileEntry const &file_entry) const |
Compare two file entries for equality. More... | |
virtual bool | isValid () const |
Check whether this entry is valid. More... | |
virtual void | read (std::istream &is) |
Read this FileEntry from the input stream. More... | |
virtual void | setComment (std::string const &comment) |
Set the comment field for the FileEntry. More... | |
virtual void | setCompressedSize (size_t size) |
Set the size when the file is compressed. More... | |
virtual void | setCrc (crc32_t crc) |
Save the CRC of the entry. More... | |
void | setEntryOffset (std::streampos offset) |
Defines the position of the entry in a Zip archive. More... | |
virtual void | setExtra (buffer_t const &extra) |
Set the extra field buffer. More... | |
virtual void | setLevel (CompressionLevel level) |
Define the level of compression to use by this FileEntry. More... | |
virtual void | setMethod (StorageMethod method) |
Sets the storage method field for the entry. More... | |
virtual void | setSize (size_t size) |
Sets the size field for the entry. More... | |
virtual void | setTime (dostime_t time) |
Set the FileEntry time using a DOS time. More... | |
virtual void | setUnixTime (std::time_t time) |
Sets the time field in Unix time format for the entry. More... | |
virtual std::string | toString () const |
Returns a human-readable string representation of the entry. More... | |
virtual void | write (std::ostream &os) |
Write this FileEntry to the output stream. More... | |
Static Public Attributes | |
static CompressionLevel const | COMPRESSION_LEVEL_DEFAULT = -3 |
static CompressionLevel const | COMPRESSION_LEVEL_FASTEST = -1 |
static CompressionLevel const | COMPRESSION_LEVEL_MAXIMUM = 100 |
static CompressionLevel const | COMPRESSION_LEVEL_MINIMUM = 1 |
static CompressionLevel const | COMPRESSION_LEVEL_NONE = 0 |
static CompressionLevel const | COMPRESSION_LEVEL_SMALLEST = -2 |
Protected Attributes | |
std::string | m_comment |
StorageMethod | m_compress_method = StorageMethod::STORED |
CompressionLevel | m_compression_level = COMPRESSION_LEVEL_DEFAULT |
uint32_t | m_crc_32 = 0 |
std::streampos | m_entry_offset = 0 |
buffer_t | m_extra_field |
FilePath | m_filename |
bool | m_has_crc_32 = false |
size_t | m_uncompressed_size = 0 |
time_t | m_unix_time = 0 |
bool | m_valid = false |
The interface is a copy of the ZipEntry interface from the java.util.zip package. The name has been changed to FileEntry, as FileCollection is a more general abstraction, that covers other types of file collections than just zip files.
Definition at line 74 of file fileentry.hpp.
typedef std::vector<unsigned char> zipios::FileEntry::buffer_t |
Definition at line 79 of file fileentry.hpp.
Values defined using this time represent the compression level to be used when compressing an entry.
If unchanged, use the DEFAULT_COMPRESSION value.
It is possible to change the compression level to NO_COMPRESSION or use the setMethod() with STORED to avoid any compression (i.e. create a zip file which awfully looks like a tarball).
Definition at line 85 of file fileentry.hpp.
typedef uint32_t zipios::FileEntry::crc32_t |
Definition at line 80 of file fileentry.hpp.
typedef uint32_t zipios::FileEntry::dostime_t |
Definition at line 81 of file fileentry.hpp.
typedef std::shared_ptr<FileEntry> zipios::FileEntry::pointer_t |
Definition at line 77 of file fileentry.hpp.
typedef std::vector<pointer_t> zipios::FileEntry::vector_t |
Definition at line 78 of file fileentry.hpp.
zipios::FileEntry::FileEntry | ( | FilePath const & | filename, |
std::string const & | comment = std::string() |
||
) |
This funciton initializes a FileEntry object. By default you may define the filename of the FileEntry object.
In case of an on disk directory, the filename should be the path to the file that can be read from disk, otherwise the FileEntry object will be viewed as invalid. There is, otherwise, no restriction to the filename.
[in] | filename | The file entry filename. |
[in] | comment | The comment attached to the file. |
Definition at line 100 of file fileentry.cpp.
|
virtual |
The destructor is defined as it has to be virtual.
It will eventually clean up resources used by the FileEntry class.
Definition at line 134 of file fileentry.cpp.
|
pure virtual |
This function creates a heap allocated clone of the object this method is called for.
Note that the object is expected to overload this function in order to create a clone of the correct type.
Implemented in zipios::ZipLocalEntry, zipios::ZipCentralDirectoryEntry, and zipios::DirectoryEntry.
Referenced by zipios::FileCollection::addEntry().
|
virtual |
This function returns the comment of this entry.
If the entry was not assigned a comment, this function returns an empty string. All entries can be given a comment, although for most it will be ignored unless you save the file to a Zip archive.
Definition at line 150 of file fileentry.cpp.
References m_comment.
|
virtual |
This function returns the compressed size of the entry. If the entry is not stored in a compressed format, the uncompressed size is returned.
Reimplemented in zipios::ZipLocalEntry.
Definition at line 164 of file fileentry.cpp.
References getSize().
Referenced by toString().
|
virtual |
This function returns the CRC 32 of this entry, if it has one.
The CRC is set only after the file is compressed so it may not always be available. The hasCrc() function can be used to know whether it was set before.
Definition at line 182 of file fileentry.cpp.
References m_crc_32.
std::streampos zipios::FileEntry::getEntryOffset | ( | ) | const |
This function retrieves the offset at which this FileEntry resides in the Zip archive it is attached to.
Note that in case of a Zip archive embedded in another file, the offset is virtual (relative to the start of the Zip archive in the larger file.)
Definition at line 202 of file fileentry.cpp.
References m_entry_offset.
|
virtual |
This function returns a copy of the vector of bytes of extra data that are stored with the entry.
This buffer should be generated using the still non-existant ZipExtra class. This includes definitions of additional meta data necessary on various operating systems. For example, Linux makes use of the "UT" (Universal Time) to save the atime, ctime, and mtime parameters, and "ux" (Unix) to save the Unix permissions and user identifier (uid) and group identifier (gid).
Definition at line 222 of file fileentry.cpp.
References m_extra_field.
|
virtual |
This function returns the filename only of the entry.
Definition at line 320 of file fileentry.cpp.
References zipios::FilePath::filename(), and m_filename.
|
virtual |
This function determines the size of the Zip archive header necessary for that file.
By default the function returns zero meaning that no header is defined.
Reimplemented in zipios::ZipLocalEntry, and zipios::ZipCentralDirectoryEntry.
Definition at line 237 of file fileentry.cpp.
|
virtual |
Use this function to read the compression level to use to compress a file.
Note that the compression level is rarely saved in the destination file, so after reading a file from a Zip archive this parameter is set to the default compression level which does not represent the level used to create the file.
The compression level is a number between 1 and 100 if compression is wanted. 0 for no compression. A few negative numbers represent various default compression levels.
Definition at line 262 of file fileentry.cpp.
References COMPRESSION_LEVEL_NONE, isDirectory(), and m_compression_level.
|
virtual |
This function returns the method used to store the entry data in the FileCollection it is attached to.
Definition at line 282 of file fileentry.cpp.
References isDirectory(), m_compress_method, and zipios::STORED.
Referenced by zipios::ZipInputStreambuf::underflow(), and zipios::ZipInputStreambuf::ZipInputStreambuf().
|
virtual |
The function returns the full filename of the entry, including a path if the entry is stored in a sub-folder.
Definition at line 303 of file fileentry.cpp.
References m_filename.
|
virtual |
This function returns the uncompressed size of the entry data.
Definition at line 332 of file fileentry.cpp.
References m_uncompressed_size.
Referenced by getCompressedSize(), and zipios::ZipInputStreambuf::ZipInputStreambuf().
|
virtual |
This function returns the date and time of the entry in MSDOS date/time format.
Definition at line 349 of file fileentry.cpp.
References m_unix_time, and unix2dostime().
|
virtual |
This function returns the date and time of the entry in Unix date/time format (see time()).
Definition at line 374 of file fileentry.cpp.
References m_unix_time.
bool zipios::FileEntry::hasCrc | ( | ) | const |
This function returns true if the setCrc() function was called earlier with a valid CRC32 and the FileEntry implementation supports a CRC (i.e. a DirectoryEntry does not have a CRC).
Definition at line 388 of file fileentry.cpp.
References m_has_crc_32.
|
virtual |
This function checks the last character of the filename, if it is a separator ('/') then the function returns true meaning that the file represents a directory.
Reimplemented in zipios::ZipLocalEntry.
Definition at line 402 of file fileentry.cpp.
References zipios::FilePath::isDirectory(), and m_filename.
Referenced by getLevel(), getMethod(), setLevel(), setMethod(), and toString().
|
virtual |
This function compares most of the fields between two file entries to see whether they are equal or not.
[in] | file_entry | The file entry to compare this against. |
Reimplemented in zipios::ZipLocalEntry, and zipios::DirectoryEntry.
Definition at line 425 of file fileentry.cpp.
References m_comment, m_compress_method, m_crc_32, m_filename, m_has_crc_32, m_uncompressed_size, m_unix_time, and m_valid.
Referenced by zipios::DirectoryEntry::isEqual(), and zipios::ZipLocalEntry::isEqual().
|
virtual |
Any method or operator that initializes a FileEntry may set a flag that specifies whether the file entry is valid or not. If it is not this method returns false.
Definition at line 447 of file fileentry.cpp.
References m_valid.
Referenced by zipios::ZipInputStreambuf::ZipInputStreambuf().
|
virtual |
This function is called when the FileEntry should be initialized from the specified input stream.
IOException | The default implementation raise an IOException error because there is no reading the FileEntry from anywhere. |
[in,out] | is | The input stream. |
Reimplemented in zipios::ZipLocalEntry, and zipios::ZipCentralDirectoryEntry.
Definition at line 724 of file fileentry.cpp.
|
virtual |
This function sets the comment of this FileEntry. Note that all implementations of the FileEntry may not include support for a comment. In that case this function does nothing.
[in] | comment | A string with the new comment. |
Definition at line 461 of file fileentry.cpp.
References m_comment.
|
virtual |
This function saves the compressed size of the entry in this object.
By default the compressed size is viewed as the same as the uncompressed size (i.e. as if STORED was used for the compression method.)
[in] | size | Value to set the compressed size field of the entry to. |
Reimplemented in zipios::ZipLocalEntry.
Definition at line 480 of file fileentry.cpp.
|
virtual |
This funciton savees the CRC field in this FileEntry field.
crc | value to set the crc field to. |
Reimplemented in zipios::ZipLocalEntry.
Definition at line 492 of file fileentry.cpp.
void zipios::FileEntry::setEntryOffset | ( | std::streampos | offset | ) |
This function defines the position of the FileEntry in a Zip archive. By default the position is set to zero.
The offset is generally read from a Zip directory entry.
When used to seek in a file, the FileCollection will add the start offset defined in the VirtualSeeker. In other words this is the position in the Zip archive itself, not the final position in the file you are reading the archive from.
[in] | offset | The new archive entry offset. |
Definition at line 512 of file fileentry.cpp.
References m_entry_offset.
|
virtual |
This function is used to set the extra field.
Only one type of file entry supports an extra field buffer. The others do nothing when this function is called.
[in] | extra | The extra field is set to this value. |
Definition at line 527 of file fileentry.cpp.
References m_extra_field.
|
virtual |
This function saves the level of compression the library should use to compress the file before saving it in the output file.
InvalidStateException | This function raises this exception if the specified level is out of the allowed range. |
[in] | level | The compression level to use to compress the file data. |
Definition at line 548 of file fileentry.cpp.
References COMPRESSION_LEVEL_MAXIMUM, COMPRESSION_LEVEL_MINIMUM, COMPRESSION_LEVEL_NONE, isDirectory(), and m_compression_level.
|
virtual |
This function sets the method with which the file data is to be compressed.
The method is ignored in a file entry which cannot be compressed. (or more precisly, the method is forced as STORED.)
InvalidStateException | This exception is raised if the method parameter does not represent a supported method. At this time the library only supports STORED and DEFLATED. The getMethod() may return more types as read from a Zip archive, but it is not possible to set such types using this function. |
[in] | method | The method field is set to the specified value. |
Definition at line 585 of file fileentry.cpp.
References zipios::DEFLATED, isDirectory(), m_compress_method, and zipios::STORED.
|
virtual |
This function is used to save the size of this file on disk when uncompressed.
[in] | size | The size field is set to this value. |
Definition at line 637 of file fileentry.cpp.
References m_uncompressed_size.
|
virtual |
This function saves the specified dostime
value as the last modification date and time of this entry. This is generally used when reading that information from a Zip archive. Otherwise you probably want to use the setUnixTime() instead since it is one to one compatible with the value handle by time(), stat(), and other OS functions.
[in] | dostime | Set time field as is using this MSDOS date/time value. |
Definition at line 653 of file fileentry.cpp.
References dos2unixtime(), and setUnixTime().
|
virtual |
This function is used to set the last modification time of this entry. In most cases this comes from the stat structure field named st_mtime. If you are creating a file directly in memory, you may use the return value of time(nullptr);
.
[in] | time | The time field is set to the specified value. |
Definition at line 668 of file fileentry.cpp.
References m_unix_time.
Referenced by setTime().
|
virtual |
This function transforms the basic information of the entry in a string. Note that most of the information is lost as the function is likely to only display the filename and the size of the file, nothing more.
Definition at line 683 of file fileentry.cpp.
References getCompressedSize(), isDirectory(), m_filename, and m_uncompressed_size.
Referenced by zipios::operator<<().
|
virtual |
This function is called when the FileEntry should be saved in the specified output stream.
IOException | The default implementation raise an IOException error because there is no writing the FileEntry anywhere. |
[in,out] | os | The output stream. |
Reimplemented in zipios::ZipLocalEntry, and zipios::ZipCentralDirectoryEntry.
Definition at line 742 of file fileentry.cpp.
|
static |
Definition at line 87 of file fileentry.hpp.
Referenced by zipios::DeflateOutputStreambuf::init().
|
static |
Definition at line 89 of file fileentry.hpp.
Referenced by zipios::DeflateOutputStreambuf::init().
|
static |
Definition at line 92 of file fileentry.hpp.
Referenced by zipios::DeflateOutputStreambuf::init(), and setLevel().
|
static |
Definition at line 91 of file fileentry.hpp.
Referenced by zipios::DeflateOutputStreambuf::init(), and setLevel().
|
static |
Definition at line 90 of file fileentry.hpp.
Referenced by zipios::ZipOutputStreambuf::closeEntry(), getLevel(), zipios::DeflateOutputStreambuf::init(), zipios::ZipOutputStreambuf::overflow(), zipios::ZipOutputStreambuf::putNextEntry(), setLevel(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
static |
Definition at line 88 of file fileentry.hpp.
Referenced by zipios::DeflateOutputStreambuf::init().
|
protected |
Definition at line 132 of file fileentry.hpp.
Referenced by getComment(), zipios::ZipCentralDirectoryEntry::getHeaderSize(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), setComment(), and zipios::ZipCentralDirectoryEntry::write().
|
protected |
Definition at line 136 of file fileentry.hpp.
Referenced by getMethod(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), setMethod(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 137 of file fileentry.hpp.
Referenced by getLevel(), setLevel(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 138 of file fileentry.hpp.
Referenced by getCrc(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), zipios::ZipLocalEntry::setCrc(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 135 of file fileentry.hpp.
Referenced by getEntryOffset(), zipios::ZipCentralDirectoryEntry::read(), setEntryOffset(), and zipios::ZipCentralDirectoryEntry::write().
|
protected |
Definition at line 139 of file fileentry.hpp.
Referenced by getExtra(), zipios::ZipCentralDirectoryEntry::getHeaderSize(), zipios::ZipLocalEntry::getHeaderSize(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), setExtra(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 131 of file fileentry.hpp.
Referenced by zipios::DirectoryEntry::DirectoryEntry(), getFileName(), zipios::ZipCentralDirectoryEntry::getHeaderSize(), zipios::ZipLocalEntry::getHeaderSize(), getName(), isDirectory(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), toString(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 140 of file fileentry.hpp.
Referenced by hasCrc(), isEqual(), and zipios::ZipLocalEntry::setCrc().
|
protected |
Definition at line 133 of file fileentry.hpp.
Referenced by zipios::DirectoryEntry::DirectoryEntry(), getSize(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), setSize(), toString(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 134 of file fileentry.hpp.
Referenced by zipios::DirectoryEntry::DirectoryEntry(), getTime(), getUnixTime(), isEqual(), zipios::ZipCentralDirectoryEntry::read(), zipios::ZipLocalEntry::read(), setUnixTime(), zipios::ZipCentralDirectoryEntry::write(), and zipios::ZipLocalEntry::write().
|
protected |
Definition at line 141 of file fileentry.hpp.
Referenced by zipios::DirectoryEntry::DirectoryEntry(), isEqual(), isValid(), zipios::ZipCentralDirectoryEntry::read(), and zipios::ZipLocalEntry::read().