csArchive Class Reference
This class can be used to work with standard ZIP archives. More...
Public Member Functions
|csArchive (const char *filename)|
|Open the archive. |
|bool||DeleteFile (const char *name)|
|Delete a file from the archive. |
|void||Dir () const|
|Type a directory listing of the archive to the console. |
|bool||FileExists (const char *name, size_t *size=0) const|
|Return true if a path exists. |
|void *||FindName (const char *name) const|
|Find a file in archive; returns a handle or 0. |
|Execute all pending operations involving writes to archive Neither DeleteFile or NewFile will have effect until this function will be called. |
|char *||GetComment () const|
|Query archive comment. |
|void *||GetFile (size_t no)|
|Get Nth file in archive or 0. |
|char *||GetFileName (void *entry) const|
|Query name from handle. |
|size_t||GetFileSize (void *entry) const|
|Query file size from handle. |
|void||GetFileTime (void *entry, csFileTime &ztime) const|
|Query filetime from handle. |
|char *||GetName () const|
|Query archive filename. |
|void *||NewFile (const char *name, size_t size=0, bool pack=true)|
|Create a new file in the archive. |
|csPtr< iDataBuffer >||Read (const char *name)|
|Read a file completely. |
|template<typename Allocator >|
|csPtr< iDataBuffer >||Read (const char *name, Allocator &alloc)|
|Read a file completely into a buffer allocated with the given allocator. |
|char *||Read (const char *name, size_t *size=0)|
|Read a file completely. |
|void||SetFileTime (void *entry, const csFileTime &ztime)|
|Set filetime for handle. |
|bool||Write (void *entry, const char *data, size_t size)|
|Write data to a file. |
|Close the archive. |
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.
- 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.
- Doesn't like files >4GB.
Constructor & Destructor Documentation
|csArchive::csArchive||(||const char *||filename||)|
Open the archive.
Close the archive.
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.
Type a directory listing of the archive to the console.
|bool csArchive::FileExists||(||const char *||name,|
|size_t *|| size = |
Return true if a path exists.
Also return the size of the file if needed.
|void* csArchive::FindName||(||const char *||name||)||const|
Find a file in archive; returns a handle or 0.
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().
|char* csArchive::GetComment||(||)|| const
|char* csArchive::GetFileName||(||void *||entry||)|| const
|size_t csArchive::GetFileSize||(||void *||entry||)|| const
|void csArchive::GetFileTime||(||void *||entry,|
|char* csArchive::GetName||(||)|| const
|void* csArchive::NewFile||(||const char *||name,|
|size_t|| size =
|bool|| pack = |
Create a new file in the archive.
If the file already exists it will be overwritten.
Returns 0 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.
|csPtr<iDataBuffer> csArchive::Read||(||const char *||name,|
|char* csArchive::Read||(||const char *||name,|
|size_t *|| size = |
Read a file completely.
After finishing with the returned data you need to 'delete' it. If the file does not exists this function returns 0. If "size" is not null, it is set to unpacked size of the file.
|void csArchive::SetFileTime||(||void *||entry,|
|const csFileTime &||ztime|
|bool csArchive::Write||(||void *||entry,|
|const char *||data,|
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:
Generated for Crystal Space 2.1 by doxygen 1.6.1