This class can be used to work with standard ZIP archives.
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.
Operations which changes archive file will be deferred until Flush() method is called. Before calling Flush() you can do any number of deletions and writes, but read operations will not be affected by these until Flush() will be called.
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 csArchive class requires approximatively 20K of stack space when invoked.
Member Function Documentation
bool csArchive::DeleteFile (
const char * name )
Delete a file from the archive.
You won't see any changes to archive until 'Flush' will be called.
bool csArchive::FileExists (
const char * name,
size_t * size = NULL ) const
Return true if a file exists.
Also return the size of the file if needed.
bool csArchive::Flush (
)
Execute all pending operations involving writes to archive Neither DeleteFile or NewFile 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 Flush(), i.e. for example user can be prompted to free some space on drive then retry Flush().
void * csArchive::NewFile (
const char * name,
size_t size = 0,
bool pack = true )
Create a new file in the archive.
If the file already exists it will be overwritten. Calling NewFile twice with same filename without calling Flush() inbetween will cause unpredictable results.
Returns NULL if not succesful. Otherwise it returns a pointer that can be passed to 'Write' routine. You won't see any changes to archive until 'Flush' will be called.
'size' is the _advisory_ file size. There is no problem if you will write more or less bytes, its just a matter of performance - if you set the right size, archive manager will have to allocate memory only once; however if you set size to zero and then write all the data in one call, it will have same performance.
char * csArchive::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 csArchive::Write (
void * entry,
const char * data,
size_t size )
Write data to a file.
Note that 'size' need not be the overall file size if this was given in 'NewFile', but this function will fail if the total size of written data exceeds the maximum size given to 'NewFile'.
The documentation for this class was generated from the following file: