CrystalSpace

Public API Reference

csArchive Class Reference

This class can be used to work with standard ZIP archives. More...

#include <csutil/archive.h>

List of all members.

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.
bool Flush ()
 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.
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.
 ~csArchive ()
 Close the archive.

Static Public Attributes

static const char hdr_central [4]
static const char hdr_endcentral [4]
static const char hdr_extlocal [4]
static const char hdr_local [4]

Friends

class ArchiveEntry


Detailed Description

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:

Definition at line 55 of file archive.h.


Constructor & Destructor Documentation

csArchive::csArchive ( const char *  filename  ) 

Open the archive.

csArchive::~csArchive (  ) 

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.

void csArchive::Dir (  )  const

Type a directory listing of the archive to the console.

bool csArchive::FileExists ( const char *  name,
size_t *  size = 0 
) const

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.

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

char* csArchive::GetComment (  )  const [inline]

Query archive comment.

Definition at line 216 of file archive.h.

void* csArchive::GetFile ( size_t  no  )  [inline]

Get Nth file in archive or 0.

Definition at line 196 of file archive.h.

char* csArchive::GetFileName ( void *  entry  )  const [inline]

Query name from handle.

Definition at line 202 of file archive.h.

size_t csArchive::GetFileSize ( void *  entry  )  const [inline]

Query file size from handle.

Definition at line 205 of file archive.h.

void csArchive::GetFileTime ( void *  entry,
csFileTime ztime 
) const [inline]

Query filetime from handle.

Definition at line 220 of file archive.h.

References ArchiveEntry.

char* csArchive::GetName (  )  const [inline]

Query archive filename.

Definition at line 213 of file archive.h.

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.

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.

char* csArchive::Read ( const char *  name,
size_t *  size = 0 
)

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 
) [inline]

Set filetime for handle.

Definition at line 230 of file archive.h.

References ArchiveEntry.

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:
Generated for Crystal Space by doxygen 1.4.7