2 #include "zipios++/zipios-config.h" 4 #include "zipios++/meta-iostreams.h" 20 bool operator== (
const ZipLocalEntry &zlh,
const ZipCDirEntry &ze ) {
40 return ( zlh.extract_version == ze.extract_version &&
41 zlh.gp_bitfield == ze.gp_bitfield &&
42 zlh.compress_method == ze.compress_method &&
43 zlh.last_mod_ftime == ze.last_mod_ftime &&
44 zlh.last_mod_fdate == ze.last_mod_fdate &&
45 zlh.filename_len == ze.filename_len &&
47 zlh.filename == ze.filename ) ;
54 const uint32 ZipLocalEntry::signature = 0x04034b50 ;
58 void ZipLocalEntry::setDefaultExtract() {
59 extract_version = 20 ;
67 return compress_size ;
89 string::size_type pos ;
90 pos = filename.find_last_of( separator ) ;
91 if ( pos != string::npos ) {
93 return filename.substr( pos + 1 ) ;
100 return uncompress_size ;
104 return ( last_mod_fdate << 16 ) + last_mod_ftime ;
113 assert( filename.size() != 0 ) ;
114 return filename[ filename.size() - 1 ] == separator ;
123 compress_size = size ;
131 extra_field = extra ;
132 extra_field_len = extra_field.size() ;
136 compress_method =
static_cast< uint16
>( method ) ;
141 filename_len = filename.size() ;
145 uncompress_size = size ;
153 last_mod_fdate = (time >> 16) & 0x0000FFFF;
154 last_mod_ftime = time & 0x0000FFFF;
159 sout << filename <<
" (" << uncompress_size <<
" bytes, " ;
160 sout << compress_size <<
" bytes compressed)" ;
164 int ZipLocalEntry::getLocalHeaderSize()
const {
165 return 30 + filename.size() + extra_field.size() ;
168 bool ZipLocalEntry::trailingDataDescriptor()
const {
172 if ( ( gp_bitfield & 4 ) == 1 )
187 const uint32 ZipCDirEntry::signature = 0x02014b50 ;
189 void ZipCDirEntry::setDefaultWriter() {
192 writer_version |=
static_cast< uint16
>( 0 ) << 8 ;
194 writer_version |=
static_cast< uint16
>( 3 ) << 8 ;
196 writer_version |= 20 ;
200 return file_comment ;
203 uint32 ZipCDirEntry::getLocalHeaderOffset()
const {
204 return rel_offset_loc_head ;
207 void ZipCDirEntry::setLocalHeaderOffset( uint32 offset ) {
208 rel_offset_loc_head = offset ;
213 file_comment = comment ;
214 file_comment_len = file_comment.size() ;
220 sout << filename <<
" (" << uncompress_size <<
" bytes, " ;
221 sout << compress_size <<
" bytes compressed)" ;
226 int ZipCDirEntry::getCDirHeaderSize()
const {
227 return 46 + filename.size() + extra_field.size() + file_comment.size() ;
240 const uint32 EndOfCentralDirectory::signature = 0x06054b50 ;
242 bool EndOfCentralDirectory::read( vector<unsigned char> &buf,
int pos ) {
243 if ( ( buf.size() - pos <
sizeof( uint32 ) ) ||
244 ( ! checkSignature( &( buf[ pos ] ) ) ) )
247 eocd_offset_from_end = buf.size() - pos ;
248 pos +=
sizeof( uint32 ) ;
249 disk_num = ztohs( &( buf[ pos ] ) ) ; pos +=
sizeof( uint16 ) ;
250 cdir_disk_num = ztohs( &( buf[ pos ] ) ) ; pos +=
sizeof( uint16 ) ;
251 cdir_entries = ztohs( &( buf[ pos ] ) ) ; pos +=
sizeof( uint16 ) ;
252 cdir_tot_entries = ztohs( &( buf[ pos ] ) ) ; pos +=
sizeof( uint16 ) ;
253 cdir_size = ztohl( &( buf[ pos ] ) ) ; pos +=
sizeof( uint32 ) ;
254 cdir_offset = ztohl( &( buf[ pos ] ) ) ; pos +=
sizeof( uint32 ) ;
255 zip_comment_len = ztohs( &( buf[ pos ] ) ) ; pos +=
sizeof( uint16 ) ;
262 bool EndOfCentralDirectory::checkSignature (
unsigned char *buf )
const {
264 return checkSignature( ztohl( buf ) ) ;
virtual string getComment() const
Returns the comment of the entry, if it has one.
virtual void setTime(int time)
Sets the time field for the entry.
virtual bool isDirectory() const
Returns true if the entry is a directory.
virtual void setCompressedSize(uint32 size)
Set the compressed size field of the entry.
virtual FileEntry * clone() const
Create a heap allocated clone of the object this method is called for.
Header file that defines some simple data types.
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
virtual string getName() const
Returns the full filename of the entry, including a path if the entry is stored in a subfolder...
Header file containing classes and functions for reading the central directory and local header field...
virtual vector< unsigned char > getExtra() const
Returns a vector of bytes of extra data that may be stored with the entry.
virtual string getFileName() const
Returns the filename of the entry.
Specialization of ZipLocalEntry, that add fields for storing the extra information, that is only present in the entries in the zip central directory and not in the local entry headers.
OutputStringStream is typedefed to ostringstream if sstream is part of the standard library (unless Z...
Header file that defines OutputStringStream.
virtual void setSize(uint32 size)
Sets the size field for the entry.
virtual int getTime() const
Returns the date and time of FIXME: what?
virtual string toString() const
Returns a human-readable string representation of the entry.
Header file that defines I/O functions for the header structures defined in ziphead.h.
virtual void setCrc(uint32 crc)
Sets the crc field.
virtual uint32 getSize() const
Returns the (uncompressed) size of the entry data.
virtual void setComment(const string &comment)
Sets the comment field for the FileEntry.
virtual StorageMethod getMethod() const
Returns the method used to store the entry in the FileCollection.
virtual void setName(const string &name)
Sets the name field for the entry.
virtual uint32 getCompressedSize() const
Returns the compressed size of the entry.
virtual string toString() const
Returns a human-readable string representation of the entry.
virtual FileEntry * clone() const
Create a heap allocated clone of the object this method is called for.
A concrete implementation of the abstract FileEntry base class for ZipFile entries, specifically for representing the information present in the local headers of file entries in a zip file.
string str()
Specialization of ostrstream::str() that takes care of null-terminating the string and unfreezing the...
virtual bool isValid() const
Any method or operator that initializes a FileEntry may set a flag, that specifies whether the read e...
virtual void setExtra(const vector< unsigned char > &extra)
Sets the extra field.
virtual void setComment(const string &comment)
Sets the comment field for the FileEntry.
virtual string getComment() const
Returns the comment of the entry, if it has one.
A FileEntry represents an entry in a FileCollection.
virtual uint32 getCrc() const
Returns the Crc for the entry, if it has one.
StorageMethod
The types used with FileEntry::setMethod and FileEntry::getMethod.
Header file containing miscellaneous small functions.