Zip Files

Zip files (or archives) contain one or more files that have been compressed or stored using the zip file format. Uniface supports the use of zip files for export, import, data conversion, file handling, compilation, and assignment redirection.

Zip archives are transparently included in Uniface’s file I/O system. This allows you to access files in zip archives using regular file I/O instructions, including file redirections in your assignment file.

To do so, insert the name of the zip file, followed by a colon in front of the file you want to access. For example, myzip.zip:myfile.xml. You can use this syntax anywhere in Uniface, including export, import, the command line, ProcScript code, file management instructions, and so on. The zip file must have a .zip extension.

Note:  On Windows, if a file in a zip archive is located in a specific directory, you must specify the directory as well as the file name when addressing the file in ProcScript. For example, fileload MyZip.zip:MyDir/MyFile.xml.

For performance reasons, Uniface keeps the zip file open until the user or Uniface ends the transaction. This makes it possible to append more data to the zip. Data to be stored in the zip is maintained in memory, and when the transaction ends, the data is stored, or flushed, to the zip file and the file is closed. This ensures that the performance impact of frequently opening and closing the zip file is minimized.

Locking Zip Files

To avoid conflicts in a multi-user environment, a locking and CRC checking mechanism is used to prevent users from writing to an open zip file. When a Uniface application modifies a zip file, the archive is locked. Subsequent Uniface users can read the file, viewing the contents as they were the last time the file was closed, but they cannot modify it. If a user reads a zip archive that has been modified since it was last read, the file is automatically reloaded.

A locked zip archive is unlocked at the moment data is flushed into it from the data buffer. This occurs when a flush or lflush ProcScript statement closes a specific zip archive, or when the application exits. On application exit, all open zip archives are implicitly flushed and unlocked.

Non-Uniface applications cannot recognize a Uniface lock and may modify a zip file that Uniface has open. Any changes that are made by this other application will be lost when Uniface saves and closes the file.

Thus for Uniface applications, zip files are treated as if the have cautious locking behavior. For non-Uniface applications, zip files are treated as if they have optimistic locking behavior.

Writing to Zip Files

By default, Uniface uses the character set defined by $SYS_CHARSET and the end-of-line character defined by $NEWLINE. However, you can define a different character set or end-of-line character for zip archives using the $ZIP_CHARSET and $ZIP_LINECRLF assignment settings. This can be useful if you are working in a multi-platform environment and need to ensure that all zip archives are written using a consistent format.

Copying or Exporting to Zip Files

When copying or exporting data to a zip file, the zip archive is created in the Zip64 format. This is required for zip files that are 4GB or larger.

Tip: If required, you can covert a Zip64 archive that is smaller than 4GB to the normal Zip format using the Uniface Resource Manager (URM). For example: urm copy zip64archive.zip:* ziparchive.zip: For more information, see urm copy.

Directories in Zip Files

Directories in zip files do not actually exist. Instead, a directory is an attribute of a file. For this reason, when you look in a zip file (for example, with WinZip), you see only a list of files, not a directory tree. When you look at either file properties or zip properties, you will see directories defined, but not existing separately. Deleting all files that have the same directory as an attribute automatically deletes the directory in the zip file.

However, it is possible to explicitly create a directory in a zip file using the dircreate and ldircreate ProcScript statements. A directory that is created in this way is given a dir attribute.

Related Topics