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 ;
79 return static_cast< StorageMethod
>( compress_method ) ;
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 ) ) ;