Main   Class List   Namespace List   Wiki

ZipObject Class Reference
[File I/O]

Provides access to a zip file. More...

Inheritance diagram for ZipObject:
Inheritance graph
[legend]

List of all members.

Public Member Functions

bool addFile (string filename, string pathInZip, bool replace=true)
 Add a file to the zip archive.
void closeArchive ()
 Close an already opened zip archive.
void closeFile (SimObject stream)
 Close a previously opened file within the zip archive.
bool deleteFile (string pathInZip)
 Deleted the given file from the zip archive.
bool extractFile (string pathInZip, string filename)
 Extact a file from the zip archive and save it to the requested location.
String getFileEntry (int index)
 Get information on the requested file within the zip archive.
int getFileEntryCount ()
 Get the number of files within the zip archive.
bool openArchive (string filename, string accessMode="read")
 Open a zip archive for manipulation.
SimObject openFileForRead (string filename)
 Open a file within the zip archive for reading.
SimObject openFileForWrite (string filename)
 Open a file within the zip archive for writing to.

Detailed Description

Provides access to a zip file.

A ZipObject add, delete and extract files that are within a zip archive. You may also read and write directly to the files within the archive by obtaining a StreamObject for the file.

Example:
// Open a zip archive, creating it if it doesn't exist
%archive = new ZipObject();
%archive.openArchive("testArchive.zip", Write);

// Add a file to the archive with the given name
%archive.addFile("./water.png", "water.png");

// Close the archive to save the changes
%archive.closeArchive();
Note:
Behind the scenes all of the work is being done with the ZipArchive and StreamObject classes.
See also:
StreamObject when using methods such as openFileForRead() and openFileForWrite()

Member Function Documentation

bool ZipObject::addFile ( string  filename,
string  pathInZip,
bool  replace = true 
)

Add a file to the zip archive.

Parameters:
filename The path and name of the file to add to the zip archive.
pathInZip The path and name to be given to the file within the zip archive.
replace If a file already exists within the zip archive at the same location as this new file, this parameter indicates if it should be replaced. By default, it will be replaced.
Returns:
True if the file was successfully added to the zip archive.
void ZipObject::closeArchive (  ) 

Close an already opened zip archive.

See also:
openArchive()
void ZipObject::closeFile ( SimObject  stream  ) 

Close a previously opened file within the zip archive.

Parameters:
stream The StreamObject of a previously opened file within the zip archive.
See also:
openFileForRead()
openFileForWrite()
bool ZipObject::deleteFile ( string  pathInZip  ) 

Deleted the given file from the zip archive.

Parameters:
pathInZip The path and name of the file to be deleted from the zip archive.
Returns:
True of the file was successfully deleted.
Note:
Files that have been deleted from the archive will still show up with a getFileEntryCount() until you close the archive. If you need to have the file count up to date with only valid files within the archive, you could close and then open the archive again.
See also:
getFileEntryCount()
closeArchive()
openArchive()
bool ZipObject::extractFile ( string  pathInZip,
string  filename 
)

Extact a file from the zip archive and save it to the requested location.

Parameters:
pathInZip The path and name of the file to be extracted within the zip archive.
filename The path and name to give the extracted file.
Returns:
True if the file was successfully extracted.
String ZipObject::getFileEntry ( int  index  ) 

Get information on the requested file within the zip archive.

This methods provides five different pieces of information for the requested file:

  • filename - The path and name of the file within the zip archive
  • uncompressed size
  • compressed size
  • compression method
  • CRC32

Use getFileEntryCount() to obtain the total number of files within the archive.

Parameters:
index The index of the file within the zip archive. Use getFileEntryCount() to determine the number of files.
Returns:
A tab delimited list of information on the requested file, or an empty string if the file could not be found.
See also:
getFileEntryCount()
int ZipObject::getFileEntryCount (  ) 

Get the number of files within the zip archive.

Use getFileEntry() to retrive information on each file within the archive.

Returns:
The number of files within the zip archive.
Note:
The returned count will include any files that have been deleted from the archive using deleteFile(). To clear out all deleted files, you could close and then open the archive again.
See also:
getFileEntry()
closeArchive()
openArchive()
bool ZipObject::openArchive ( string  filename,
string  accessMode = "read" 
)

Open a zip archive for manipulation.

Once a zip archive is opened use the various ZipObject methods for working with the files within the archive. Be sure to close the archive when you are done with it.

Parameters:
filename The path and file name of the zip archive to open.
accessMode One of read, write or readwrite
Returns:
True is the archive was successfully opened.
Note:
If you wish to make any changes to the archive, be sure to open it with a write or readwrite access mode.
See also:
closeArchive()
SimObject ZipObject::openFileForRead ( string  filename  ) 

Open a file within the zip archive for reading.

Be sure to close the file when you are done with it.

Parameters:
filename The path and name of the file to open within the zip archive.
Returns:
A standard StreamObject is returned for working with the file.
Note:
You must first open the zip archive before working with files within it.
See also:
closeFile()
openArchive()
SimObject ZipObject::openFileForWrite ( string  filename  ) 

Open a file within the zip archive for writing to.

Be sure to close the file when you are done with it.

Parameters:
filename The path and name of the file to open within the zip archive.
Returns:
A standard StreamObject is returned for working with the file.
Note:
You must first open the zip archive before working with files within it.
See also:
closeFile()
openArchive()


Copyright © GarageGames, LLC. All Rights Reserved.