00001 #ifndef CLASSLIB_ARCHIVE_H 00002 # define CLASSLIB_ARCHIVE_H 00003 00004 //<<<<<< INCLUDES >>>>>> 00005 00006 # include "classlib/zip/ZConstants.h" 00007 # include "classlib/iobase/IOBuffer.h" 00008 # include <vector> 00009 # include <string> 00010 00011 namespace lat { 00012 //<<<<<< PUBLIC DEFINES >>>>>> 00013 //<<<<<< PUBLIC CONSTANTS >>>>>> 00014 //<<<<<< PUBLIC TYPES >>>>>> 00015 00016 class Storage; 00017 class Filename; 00018 class ZipMember; 00019 class InputStream; 00020 class OutputStream; 00021 class MemoryStorage; 00022 00023 //<<<<<< PUBLIC VARIABLES >>>>>> 00024 //<<<<<< PUBLIC FUNCTIONS >>>>>> 00025 //<<<<<< CLASS DECLARATIONS >>>>>> 00026 00076 class ZipArchive : public ZConstants 00077 { 00078 public: 00079 typedef std::vector<ZipMember *>::const_iterator Iterator; 00080 00081 // FIXME: file can be an inmemory file, e.g. compiled-in string! 00082 ZipArchive (Storage *file); 00083 ZipArchive (Filename name, unsigned mode); 00084 virtual ~ZipArchive (void); 00085 00086 // FIXME: version made, required 00087 std::string comment (void) const; 00088 void comment (const std::string &text); 00089 00090 size_t size (void) const; 00091 Iterator begin (void) const; 00092 Iterator end (void) const; 00093 Iterator find (Filename name) const; // FIXME: case? 00094 ZipMember * member (Filename name) const; // FIXME: case? 00095 00096 // FIXME: (CheckedInputStream ->) InflaterInputSream -> bounded 00097 // FileStorageInputStream 00098 InputStream * input (ZipMember *member); 00099 OutputStream * output (ZipMember *member); 00100 Storage * openStored (ZipMember *member); 00101 00102 // NB: on file close, finish writing last file, write out 00103 // zip member headers again, write out end header. 00104 void flush (void); 00105 void close (void); 00106 00107 // Other operations 00108 bool verify (void); 00109 00110 protected: 00111 virtual Storage * openStored (Storage *master, 00112 IOOffset position, 00113 IOOffset length); 00114 00115 private: 00116 class MemberByName; 00117 class ZInput; 00118 class SInput; 00119 class ZOutput; 00120 class SOutput; 00121 friend class ZInput; 00122 friend class SInput; 00123 friend class ZOutput; 00124 friend class SOutput; 00125 00126 void openArchive (void); 00127 IOOffset findEndHeader (void); 00128 void readEndHeader (IOOffset pos); 00129 void readDirectory (void); 00130 ZipMember * readMember (void); 00131 00132 void closeArchive (void); 00133 void writeDirectory (void); 00134 00135 bool verifyMember (void); 00136 void updateMember (ZipMember *member); 00137 00138 Storage *m_file; //< The archive 00139 Method m_method; //< Default compression method 00140 unsigned m_level; //< Default compression level 00141 std::string m_comment; //< Archive comment 00142 IOOffset m_prefixSize; //< Size of the archive prefix (SFX) 00143 IOOffset m_dirPos; //< Central directory position 00144 IOOffset m_dirSize; //< Central directory size 00145 IOOffset m_dirOffset; //< Central directory offset (from 00146 // the beginning of the archive, 00147 // which could be multi-file) 00148 unsigned m_mode; 00155 std::vector<ZipMember *> m_members; //< Members in this archive 00156 OutputStream *m_current; //< Stream for current member output 00157 00158 // undefined, no semantics 00159 ZipArchive (const ZipArchive &); 00160 const ZipArchive &operator= (const ZipArchive &); 00161 }; 00162 00163 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> 00164 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>> 00165 00166 } // namespace lat 00167 #endif // CLASSLIB_ARCHIVE_H