ziphead.h
Go to the documentation of this file.00001 #ifndef ZIPHEAD_H
00002 #define ZIPHEAD_H
00003
00004 #include "zipios-config.h"
00005
00006 #include "meta-iostreams.h"
00007 #include <string>
00008 #include <vector>
00009
00010 #include "fileentry.h"
00011 #include "zipios_defs.h"
00012
00013 namespace zipios {
00014
00015 using std::streampos ;
00016
00017 class ZipCDirEntry ;
00018
00022 class BaseExport ZipLocalEntry : public FileEntry {
00023 friend istream &operator>> ( istream &is, ZipLocalEntry &zcdh ) ;
00024 friend ostream &operator<< ( ostream &os, const ZipLocalEntry &zlh ) ;
00025 friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
00026 public:
00027 inline ZipLocalEntry( const string &_filename = "",
00028 const vector< unsigned char > &_extra_field =
00029 vector< unsigned char >() )
00030 : gp_bitfield( 0 ),
00031 _valid( false ) {
00032 setDefaultExtract() ;
00033 setName( _filename ) ;
00034 setExtra( _extra_field ) ;
00035 }
00036
00037 void setDefaultExtract() ;
00038 inline ZipLocalEntry &operator=( const class ZipLocalEntry &src ) ;
00039 virtual string getComment() const ;
00040 virtual uint32 getCompressedSize() const ;
00041 virtual uint32 getCrc() const ;
00042 virtual vector< unsigned char > getExtra() const ;
00043 virtual StorageMethod getMethod() const ;
00044 virtual string getName() const ;
00045 virtual string getFileName() const ;
00046 virtual uint32 getSize() const ;
00047 virtual int getTime() const ;
00048 virtual bool isValid() const ;
00049
00050 virtual bool isDirectory() const ;
00051
00052 virtual void setComment( const string &comment ) ;
00053 virtual void setCompressedSize( uint32 size ) ;
00054 virtual void setCrc( uint32 crc ) ;
00055 virtual void setExtra( const vector< unsigned char > &extra ) ;
00056 virtual void setMethod( StorageMethod method ) ;
00057 virtual void setName( const string &name ) ;
00058 virtual void setSize( uint32 size ) ;
00059 virtual void setTime( int time ) ;
00060
00061 virtual string toString() const ;
00062
00063 int getLocalHeaderSize() const ;
00064
00065 bool trailingDataDescriptor() const ;
00066
00067 virtual FileEntry *clone() const ;
00068
00069 virtual ~ZipLocalEntry() {}
00070 protected:
00071 static const uint32 signature ;
00072 uint16 extract_version ;
00073 uint16 gp_bitfield ;
00074 uint16 compress_method ;
00075 uint16 last_mod_ftime ;
00076 uint16 last_mod_fdate ;
00077 uint32 crc_32 ;
00078 uint32 compress_size ;
00079 uint32 uncompress_size ;
00080 uint16 filename_len ;
00081 uint16 extra_field_len ;
00082
00083 string filename ;
00084 vector< unsigned char > extra_field ;
00085
00086 bool _valid ;
00087 };
00088
00093 struct DataDescriptor {
00094 uint32 crc_32 ;
00095 uint32 compress_size ;
00096 uint32 uncompress_size ;
00097 };
00098
00102 class BaseExport ZipCDirEntry : public ZipLocalEntry {
00103 friend istream &operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
00104 friend ostream &operator<< ( ostream &os, const ZipCDirEntry &zcdh ) ;
00105 friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
00106 public:
00107
00108 inline ZipCDirEntry( const string &_filename = "",
00109 const string &_file_comment = "",
00110 const vector< unsigned char > &_extra_field =
00111 vector< unsigned char >() )
00112 : ZipLocalEntry ( _filename, _extra_field ),
00113 disk_num_start ( 0x0 ),
00114 intern_file_attr( 0x0 ),
00115 extern_file_attr( 0x81B40000 )
00116
00117
00118
00119 {
00120 setComment( _file_comment ) ;
00121 setDefaultWriter() ;
00122 }
00123
00124 void setDefaultWriter() ;
00125
00126 ZipCDirEntry &operator=( const class ZipCDirEntry &src ) ;
00127 virtual string toString() const ;
00128
00129 virtual string getComment() const ;
00130
00131 virtual void setComment( const string &comment ) ;
00132
00133 virtual uint32 getLocalHeaderOffset() const ;
00134 virtual void setLocalHeaderOffset( uint32 offset ) ;
00135
00136 int getCDirHeaderSize() const ;
00137
00138 virtual FileEntry *clone() const ;
00139
00140 virtual ~ZipCDirEntry() {}
00141 private:
00142 static const uint32 signature ;
00143 uint16 writer_version ;
00144
00145 uint16 file_comment_len ;
00146 uint16 disk_num_start ;
00147 uint16 intern_file_attr ;
00148 uint32 extern_file_attr ;
00149
00150 uint32 rel_offset_loc_head ;
00151
00152 string file_comment ;
00153 };
00154
00159 class EndOfCentralDirectory {
00160 friend ostream &operator<< ( ostream &os, const EndOfCentralDirectory &eocd ) ;
00161 public:
00162 explicit EndOfCentralDirectory( const string &_zip_comment = "",
00163 uint16 _disk_num = 0, uint16 _cdir_disk_num = 0,
00164 uint16 _cdir_entries = 0,
00165 uint16 _cdir_tot_entries = 0,
00166 uint32 _cdir_size = 0, uint32 _cdir_offset = 0 )
00167 : disk_num ( _disk_num ),
00168 cdir_disk_num ( _cdir_disk_num ),
00169 cdir_entries ( _cdir_entries ),
00170 cdir_tot_entries ( _cdir_tot_entries ),
00171 cdir_size ( _cdir_size ),
00172 cdir_offset ( _cdir_offset ),
00173 zip_comment_len ( _zip_comment.size() ),
00174 zip_comment ( _zip_comment ) {}
00175
00176 uint32 offset() const { return cdir_offset ; }
00177 uint16 totalCount() const { return cdir_tot_entries ; }
00178 void setCDirSize( uint32 size ) { cdir_size = size ; }
00179 void setOffset( uint32 offset ) { cdir_offset = offset ; }
00180
00181 void setTotalCount( uint16 c ) { cdir_entries = c ; cdir_tot_entries = c ; }
00182 int eocdOffSetFromEnd() const { return eocd_offset_from_end ; }
00183 bool read( vector<unsigned char> &buf, int pos ) ;
00184 private:
00185 static const uint32 signature;
00186 uint16 disk_num ;
00187 uint16 cdir_disk_num ;
00188 uint16 cdir_entries ;
00189 uint16 cdir_tot_entries ;
00190 uint32 cdir_size ;
00191 uint32 cdir_offset ;
00192 uint16 zip_comment_len ;
00193
00194 streampos eocd_offset_from_end ;
00195 string zip_comment;
00196 bool checkSignature( unsigned char *buf ) const ;
00197 inline bool checkSignature( uint32 sig ) const ;
00198 };
00199
00200
00201 bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
00202 inline bool operator== ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
00203 return zlh == ze ;
00204 }
00205 inline bool operator!= ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) {
00206 return ! ( zlh == ze ) ;
00207 }
00208 inline bool operator!= ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
00209 return ! ( zlh == ze ) ;
00210 }
00211
00212
00213
00214
00215 }
00216
00217 #endif
00218
00219
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242