Accessing ZIP Files |
|
A ZIP file (.ZIP) is a compressed archive file format. A ZIP file usually contains a single or multiple file/directory entries that have been compressed. ZIP files are often used for email attachments and backup archival purposes.
PxPlus ZIP File Support
Using PxPlus, you can:
PxPlus uses a record/index to represent a file/directory entry within a ZIP file. The order of the records depends on the order that the file/directory entries were added to the ZIP archive.
PxPlus uses the key to represent the file/directory name of an entry in the ZIP file.
(PxPlus ZIP file support was added in PxPlus 2014.)
To create a ZIP file, use the OPEN CREATE directive with OPT="ZIP":
OPEN CREATE (chan, OPT="ZIP") "myZIPFile.zip"
To open a ZIP file, use the standard OPEN directive:
OPEN (chan) "myZIPFile.zip"
Use the FIN( ) system function to get metadata about the compressed files/directories within the ZIP archive. The file/directory entry that you get metadata about is the next record. If there is no next record, a null value is returned.
The "ZIPFilename" keyword returns the file/directory name of the next ZIP archive entry. Directory names will always end in a '/' (forward slash).
FIN (chan, "ZIPFilename")
The "ZIPInfo" keyword will return all of the metadata about a file/directory in a ZIP archive.
FIN (chan, "ZIPInfo")
The key system functions KEF( ), KEP( ), KEC( ), KEY( ), KEN( ) and KEL( ) can also be used to return the file/directory name of ZIP archive entries. KEY(chan) and FIN(chan, "ZIPFilename") are equivalent and will return the same file/directory name.
You can extract a file in two ways:
If the file/record is a directory, the EXTRACT FILE directive will result in an Error #3: Input/Output error on file. The READ RECORD directive will return an empty string.
To use EXTRACT FILE, you must know the name of the file in the ZIP archive you want to extract.
EXTRACT FILE "new_filename" FROM (chan, KEY="filename")
If the path and filename of the file to extract are the same as what you want to put on your system, then you can leave out the KEY= option.
EXTRACT FILE "filename" FROM (chan)
PxPlus supports the following uses of READ RECORD for ZIP files:
READ RECORD (chan) data$
READ RECORD (chan, KEY="filename") data$
READ RECORD (chan, RNO=recNum) data$
READ RECORD (chan, IND=indNum) data$
You can append a file to the end of the ZIP archive in two ways:
or
If the file/record is a directory, the INSERT FILE directive will result in an Error #3: Input/Output error on file.
To use INSERT FILE, you must know the name of the file you want to put in the ZIP archive.
INSERT FILE "filename" TO (chan, KEY="new_filename")
If the path and filename of the file to zip are the same as what you want to put in the ZIP archive, then you can leave out the KEY= option.
INSERT FILE "filename" TO (chan)
PxPlus supports appending both files and directories:
WRITE RECORD (chan, KEY="filename") contents$
WRITE RECORD (chan, KEY="dir/") ""
To remove a file/directory entry from a ZIP archive, you can use the REMOVE directive. PxPlus supports the following uses of REMOVE for ZIP files:
REMOVE(chan)
REMOVE (chan, KEY="filename")
REMOVE (chan, IND=indNum)
*TOOLS/ZIP and
*TOOLS/UNZIP Utilities
EXTRACT FILE Directive
INSERT FILE Directive
READ RECORD Directive
REMOVE Directive
WRITE RECORD Directive