In file include/csutil/archive.h:

## class Archive

> Archive class that can be used to work with standard

### Public Methods

bool append(void *entry, const char *data, size_t size)
  Append data to a file
Archive(const char *filename, bool read_only = false, const char *base_path = "")
  Open the archive.
void delete_file(const char *name)
  Delete a file from the archive
void dir()
  Show a directory listing of the archive.
bool file_exists(const char *name, size_t *size = NULL)
  Return true if a file exists
void* find_name(const char *name)
  Find a file in archive; returns a handle or NULL
void* first_file()
  Iterator.
char* get_file_name(void *entry)
  Query name from handle
size_t get_file_size(void *entry)
  Query file size from handle
void get_file_time(void *entry, tm &ztime)
  Query filetime from handle
char* GetComment()
  Query archive comment
char* GetFilename()
  Query archive filename
void* new_file(const char *name, size_t size, bool pack = true)
  Create a new file in the archive
char* read(const char *name, size_t *size = NULL)
  Read a file completely
void set_file_time(void *entry, tm &ztime)
  Set filetime for handle
bool write(void *entry, const char *data, size_t size)
  Write data to a file
bool write_archive()
  Execute all pending operations involving writes to archive Neither delete_file or new_file will have effect until this function will be called
~Archive()
  Close the archive.

## Documentation

> 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.

`class ArchiveEntry`
  Archive entry class

`Archive(const char *filename, bool read_only = false, const char *base_path = "")`
  Open the archive.

`~Archive()`
  Close the archive.

`void dir()`
  Show a directory listing of the archive.

`void* new_file(const char *name, size_t size, bool pack = true)`
  Create a new file in the archive. If the file already exists it will be overwritten. Calling new_file twice with same filename without calling write_archive() between will cause unpredictable results. Returns NULL if not succesful. Otherwise it returns a pointer that can be given to 'write' and 'append'. You won't see any changes to archive until 'write_archive' will be called.

`void delete_file(const char *name)`
  Delete a file from the archive. You won't see any changes to archive until 'write_archive' will be called.

`bool file_exists(const char *name, size_t *size = NULL)`
  Return true if a file exists. Also return the size of the file if needed.

`char* read(const char *name, size_t *size = NULL)`
  Read a file completely. After finishing with the returned data you need to 'delete[]' it. If the file does not exists this function returns NULL. If "size" is not null, it is set to unpacked size of the file.

`bool write(void *entry, const char *data, size_t size)`
  Write data to a file. Note that 'size' need not be the total maximum size if this was given in 'new_file'.

`bool append(void *entry, const char *data, size_t size)`
  Append data to a file. This function will fail if the total size exceeds the maximum size that was given in 'new_file'.

`bool write_archive()`
  Execute all pending operations involving writes to archive Neither delete_file or new_file will have effect until this function will be called. Returns false if operation failed. If operation failed, postponed operations remains in the same state as before calling write_archive(), i.e. for example user can be prompted to free some space on drive then retry write_archive().

`void* first_file()`
  Iterator.

`void* find_name(const char *name)`
  Find a file in archive; returns a handle or NULL

`char* get_file_name(void *entry)`
  Query name from handle

`size_t get_file_size(void *entry)`
  Query file size from handle

`void get_file_time(void *entry, tm &ztime)`
  Query filetime from handle

`void set_file_time(void *entry, tm &ztime)`
  Set filetime for handle

`char* GetFilename()`
  Query archive filename

`char* GetComment()`
  Query archive comment

This class has no child classes.

alphabetic index hierarchy of classes

this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de