ziphead.h
Go to the documentation of this file.
#ifndef ZIPHEAD_H
#define ZIPHEAD_H
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include <string>
#include <vector>
#include "zipios++/fileentry.h"
#include "zipios++/zipios_defs.h"
namespace zipios {
using std::streampos ;
class ZipCDirEntry ;
class ZipLocalEntry : public FileEntry {
friend istream &operator>> ( istream &is, ZipLocalEntry &zcdh ) ;
friend ostream &operator<< ( ostream &os, const ZipLocalEntry &zlh ) ;
friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
public:
inline ZipLocalEntry( const string &_filename = "",
const vector< unsigned char > &_extra_field =
vector< unsigned char >() )
: gp_bitfield( 0 ),
_valid( false ) {
setDefaultExtract() ;
setName( _filename ) ;
setExtra( _extra_field ) ;
}
void setDefaultExtract() ;
inline ZipLocalEntry &operator=( const class ZipLocalEntry &src ) ;
virtual string getComment() const ;
virtual uint32 getCompressedSize() const ;
virtual uint32 getCrc() const ;
virtual vector< unsigned char > getExtra() const ;
virtual StorageMethod getMethod() const ;
virtual string getName() const ;
virtual string getFileName() const ;
virtual uint32 getSize() const ;
virtual int getTime() const ;
virtual bool isValid() const ;
virtual bool isDirectory() const ;
virtual void setComment( const string &comment ) ;
virtual void setCompressedSize( uint32 size ) ;
virtual void setCrc( uint32 crc ) ;
virtual void setExtra( const vector< unsigned char > &extra ) ;
virtual void setMethod( StorageMethod method ) ;
virtual void setName( const string &name ) ;
virtual void setSize( uint32 size ) ;
virtual void setTime( int time ) ;
virtual string toString() const ;
int getLocalHeaderSize() const ;
bool trailingDataDescriptor() const ;
virtual FileEntry *clone() const ;
virtual ~ZipLocalEntry() {}
protected:
static const uint32 signature ;
uint16 extract_version ;
uint16 gp_bitfield ;
uint16 compress_method ;
uint16 last_mod_ftime ;
uint16 last_mod_fdate ;
uint32 crc_32 ;
uint32 compress_size ;
uint32 uncompress_size ;
uint16 filename_len ;
uint16 extra_field_len ;
string filename ;
vector< unsigned char > extra_field ;
bool _valid ;
};
struct DataDescriptor {
uint32 crc_32 ;
uint32 compress_size ;
uint32 uncompress_size ;
};
class ZipCDirEntry : public ZipLocalEntry {
friend istream &operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
friend ostream &operator<< ( ostream &os, const ZipCDirEntry &zcdh ) ;
friend bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
public:
inline ZipCDirEntry( const string &_filename = "",
const string &_file_comment = "",
const vector< unsigned char > &_extra_field =
vector< unsigned char >() )
: ZipLocalEntry ( _filename, _extra_field ),
disk_num_start ( 0x0 ),
intern_file_attr( 0x0 ),
extern_file_attr( 0x81B40000 )
// FIXME: I don't understand the external mapping, simply
// copied value for a file with -rw-rw-r-- permissions
// compressed with info-zip
{
setComment( _file_comment ) ;
setDefaultWriter() ;
}
void setDefaultWriter() ;
inline ZipCDirEntry &operator=( const class ZipCDirEntry &src ) ;
virtual string toString() const ;
virtual string getComment() const ;
virtual void setComment( const string &comment ) ;
virtual uint32 getLocalHeaderOffset() const ;
virtual void setLocalHeaderOffset( uint32 offset ) ;
int getCDirHeaderSize() const ;
virtual FileEntry *clone() const ;
virtual ~ZipCDirEntry() {}
private:
static const uint32 signature ;
uint16 writer_version ;
uint16 file_comment_len ;
uint16 disk_num_start ;
uint16 intern_file_attr ;
uint32 extern_file_attr ;
uint32 rel_offset_loc_head ;
string file_comment ;
};
class EndOfCentralDirectory {
friend ostream &operator<< ( ostream &os, const EndOfCentralDirectory &eocd ) ;
public:
explicit EndOfCentralDirectory( const string &_zip_comment = "",
uint16 _disk_num = 0, uint16 _cdir_disk_num = 0,
uint16 _cdir_entries = 0,
uint16 _cdir_tot_entries = 0,
uint32 _cdir_size = 0, uint32 _cdir_offset = 0 )
: disk_num ( _disk_num ),
cdir_disk_num ( _cdir_disk_num ),
cdir_entries ( _cdir_entries ),
cdir_tot_entries ( _cdir_tot_entries ),
cdir_size ( _cdir_size ),
cdir_offset ( _cdir_offset ),
zip_comment_len ( _zip_comment.size() ),
zip_comment ( _zip_comment ) {}
uint32 offset() const { return cdir_offset ; }
uint16 totalCount() const { return cdir_tot_entries ; }
void setCDirSize( uint32 size ) { cdir_size = size ; }
void setOffset( uint32 offset ) { cdir_offset = offset ; }
void setTotalCount( uint16 c ) { cdir_entries = c ; cdir_tot_entries = c ; }
int eocdOffSetFromEnd() const { return eocd_offset_from_end ; }
bool read( vector<unsigned char> &buf, int pos ) ;
private:
static const uint32 signature;
uint16 disk_num ;
uint16 cdir_disk_num ;
uint16 cdir_entries ;
uint16 cdir_tot_entries ;
uint32 cdir_size ;
uint32 cdir_offset ;
uint16 zip_comment_len ;
streampos eocd_offset_from_end ; // Not a Zip defined field
string zip_comment;
bool checkSignature( unsigned char *buf ) const ;
inline bool checkSignature( uint32 sig ) const ;
};
bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) ;
inline bool operator== ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
return zlh == ze ;
}
inline bool operator!= ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) {
return ! ( zlh == ze ) ;
}
inline bool operator!= ( const ZipCDirEntry &ze, const ZipLocalEntry &zlh ) {
return ! ( zlh == ze ) ;
}
// Inline member functions
ZipCDirEntry &ZipCDirEntry::operator=( const class ZipCDirEntry &src ) {
writer_version = src.writer_version ;
extract_version = src.extract_version ;
gp_bitfield = src.gp_bitfield ;
compress_method = src.compress_method ;
last_mod_ftime = src.last_mod_ftime ;
last_mod_fdate = src.last_mod_fdate ;
crc_32 = src.crc_32 ;
compress_size = src.compress_size ;
uncompress_size = src.uncompress_size ;
filename_len = src.filename_len ;
extra_field_len = src.extra_field_len ;
file_comment_len = src.file_comment_len ;
disk_num_start = src.disk_num_start ;
intern_file_attr = src.intern_file_attr ;
extern_file_attr = src.extern_file_attr ;
rel_offset_loc_head = src.rel_offset_loc_head ;
filename = src.filename ;
extra_field = src.extra_field ;
file_comment = src.file_comment ;
return *this ;
}
bool EndOfCentralDirectory::checkSignature ( uint32 sig ) const {
return signature == sig ;
}
} // namespace
#endif
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
zipios::FileEntry
A FileEntry represents an entry in a FileCollection.
Definition fileentry.h:52
zipios::ZipCDirEntry
Specialization of ZipLocalEntry, that add fields for storing the extra information,...
Definition ziphead.h:102
zipios::ZipCDirEntry::clone
virtual FileEntry * clone() const
Create a heap allocated clone of the object this method is called for.
Definition ziphead.cpp:231
zipios::ZipCDirEntry::getComment
virtual string getComment() const
Returns the comment of the entry, if it has one.
Definition ziphead.cpp:199
zipios::ZipCDirEntry::setComment
virtual void setComment(const string &comment)
Sets the comment field for the FileEntry.
Definition ziphead.cpp:212
zipios::ZipCDirEntry::toString
virtual string toString() const
Returns a human-readable string representation of the entry.
Definition ziphead.cpp:218
zipios::ZipLocalEntry
A concrete implementation of the abstract FileEntry base class for ZipFile entries,...
Definition ziphead.h:22
zipios::ZipLocalEntry::getMethod
virtual StorageMethod getMethod() const
Returns the method used to store the entry in the FileCollection.
Definition ziphead.cpp:78
zipios::ZipLocalEntry::getExtra
virtual vector< unsigned char > getExtra() const
Returns a vector of bytes of extra data that may be stored with the entry.
Definition ziphead.cpp:74
zipios::ZipLocalEntry::setExtra
virtual void setExtra(const vector< unsigned char > &extra)
Sets the extra field.
Definition ziphead.cpp:130
zipios::ZipLocalEntry::getTime
virtual int getTime() const
Returns the date and time of FIXME: what?
Definition ziphead.cpp:103
zipios::ZipLocalEntry::getFileName
virtual string getFileName() const
Returns the filename of the entry.
Definition ziphead.cpp:86
zipios::ZipLocalEntry::setComment
virtual void setComment(const string &comment)
Sets the comment field for the FileEntry.
Definition ziphead.cpp:118
zipios::ZipLocalEntry::isValid
virtual bool isValid() const
Any method or operator that initializes a FileEntry may set a flag, that specifies whether the read e...
Definition ziphead.cpp:108
zipios::ZipLocalEntry::setSize
virtual void setSize(uint32 size)
Sets the size field for the entry.
Definition ziphead.cpp:144
zipios::ZipLocalEntry::setTime
virtual void setTime(int time)
Sets the time field for the entry.
Definition ziphead.cpp:148
zipios::ZipLocalEntry::getCompressedSize
virtual uint32 getCompressedSize() const
Returns the compressed size of the entry.
Definition ziphead.cpp:66
zipios::ZipLocalEntry::setMethod
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
Definition ziphead.cpp:135
zipios::ZipLocalEntry::getComment
virtual string getComment() const
Returns the comment of the entry, if it has one.
Definition ziphead.cpp:62
zipios::ZipLocalEntry::getName
virtual string getName() const
Returns the full filename of the entry, including a path if the entry is stored in a subfolder.
Definition ziphead.cpp:82
zipios::ZipLocalEntry::toString
virtual string toString() const
Returns a human-readable string representation of the entry.
Definition ziphead.cpp:157
zipios::ZipLocalEntry::clone
virtual FileEntry * clone() const
Create a heap allocated clone of the object this method is called for.
Definition ziphead.cpp:178
zipios::ZipLocalEntry::getCrc
virtual uint32 getCrc() const
Returns the Crc for the entry, if it has one.
Definition ziphead.cpp:70
zipios::ZipLocalEntry::isDirectory
virtual bool isDirectory() const
Returns true if the entry is a directory.
Definition ziphead.cpp:112
zipios::ZipLocalEntry::setCrc
virtual void setCrc(uint32 crc)
Sets the crc field.
Definition ziphead.cpp:126
zipios::ZipLocalEntry::setCompressedSize
virtual void setCompressedSize(uint32 size)
Set the compressed size field of the entry.
Definition ziphead.cpp:122
zipios::ZipLocalEntry::getSize
virtual uint32 getSize() const
Returns the (uncompressed) size of the entry data.
Definition ziphead.cpp:99
zipios::ZipLocalEntry::setName
virtual void setName(const string &name)
Sets the name field for the entry.
Definition ziphead.cpp:139
fileentry.h
Header file that defines FileEntry.
zipios::StorageMethod
StorageMethod
The types used with FileEntry::setMethod and FileEntry::getMethod.
Definition fileentry.h:25
zipios::DataDescriptor
A struct containing fields for the entries in a zip file data descriptor, that trails the compressed ...
Definition ziphead.h:93
zipios_defs.h
Header file that defines some simple data types.