class Archive Archive class that can be used to work with standard
Archive class that can be used to work with standard .ZIP format files. Constructor accepts a file name - if such a file is not found, it is created. After this you can examine archive directory, read files, delete or write files in archive.Operation which changes archive file will be postponed until write_archive() will be called. Before calling write_archive() you can do any number of deletions and writes, but read operations will not be affected by these until write_archive() will be called.
Two access modes are allowed:
1) Read/write mode. This is selected by setting "readonly" parameter at object creation to false (this is default if you don't explicitly set it). In this mode any deletions/additions will be made to the original archive file.
2) Readonly mode. This is selected by setting "readonly" constructor parameter to true and possibly defining a base path on a writeable media which will be used for reflecting the changes to the archive.
When you make any changes to the archive, on call to write_archive () a subdirectory is created in directory you specified at object construction time with same name as archive but without extension. In this directory a file is created called $(ZIP_HEADER_FILENAME), which contains the updated ZIP archive directory. All files that were added to the ZIP file will be also written into that directory, or in even deeper subdirectories if they were added into archive with subdirectories. For example, if you will open archive TEST.ZIP in readonly mode and will add file abcde.doc and text/abcde.txt, at write_archive () time they will be compressed and written to disk as TEST/abcde.doc and TEST/text/abcde.txt.
If you want to make some additions/changes to the archive without changing the archive itself you can do any of the following:
a) Create a directory called
and put all replacement files in uncompressed form there. b) Create a directory called
and put all replacement files in compressed form there. Files should have absolutely the same name as original, i.e. for example if you want to replace file texture.gif in a readonly archive with a newer version, you should pack texture.gif into an ZIP archive, then rename that archive into texture.gif. c) Create a directory called
and put a number of arbitrary named ZIP files into that directory. In this case at object creation time (but obly in readonly mode) the object will scan replacement directory for files and overlay directories of any archives that will be found there onto the directory of main archive file. These archives can contain multiple files, not neccessarily only one file. Keep in mind, however, that such an compound archive should be used in readonly mode. Any writes to such an archive will invalidate replacement files. Known quirks:
No CRC check is done on reading, although ZIP file format allows it. This design 'flaw' was allowed to achieve maximal speed. However, when a file is added to archive, its CRC is computed and updated correctly.
Several methods of the Archive class requires approximatively 20K of stack space when invoked.
Archive(const char *filename, bool read_only = false, const char *base_path = "")
~Archive()
void dir()
void* new_file(const char *name, size_t size, bool pack = true)
void delete_file(const char *name)
bool file_exists(const char *name, size_t *size = NULL)
char* read(const char *name, size_t *size = NULL)
bool write(void *entry, const char *data, size_t size)
bool append(void *entry, const char *data, size_t size)
bool write_archive()
void* first_file()
void* find_name(const char *name)
char* get_file_name(void *entry)
size_t get_file_size(void *entry)
void get_file_time(void *entry, tm &ztime)
void set_file_time(void *entry, tm &ztime)
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de