ZipObject
Provides access to a zip file.
Public Functions
bool
addFile(string filename, string pathInZip, bool replace)
Add a file to the zip archive.
void
Close an already opened 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
Get the number of files within the zip archive.
bool
openArchive(string filename, string accessMode)
Open a zip archive for manipulation.
openFileForRead(string filename)
Open a file within the zip archive for reading.
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.
// 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.
StreamObject when using methods such as openFileForRead() and openFileForWrite()
Public Functions
addFile(string filename, string pathInZip, bool replace)
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. |
True if the file was successfully added to the zip archive.
closeArchive()
Close an already opened zip archive.
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. |
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. |
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.
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. |
True if the file was successfully extracted.
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
index | The index of the file within the zip archive. Use getFileEntryCount() to determine the number of files. |
A tab delimited list of information on the requested file, or an empty string if the file could not be found.
getFileEntryCount()
Get the number of files within the zip archive.
Use getFileEntry() to retrive information on each file within the archive.
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.
openArchive(string filename, string accessMode)
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 |
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.
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. |
A standard StreamObject is returned for working with the file.
note:You must first open the zip archive before working with files within it.
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. |
A standard StreamObject is returned for working with the file.
note:You must first open the zip archive before working with files within it.