Skip to content
Carlos Alloatti edited this page Aug 31, 2019 · 3 revisions

Creating a zip file:

_zipopen()

This function creates a temporary cursor that will be used by zipaddfile, zipaddblob and zipclose


_zipaddfile(psfilepath, [pzfilepath], [pfilecomment], [pfiletime])

psfilepath: full path of the file to add to the zip file pzfilepath: path of the file inside the zip file pfilecomment: file comment pfiletime: file datetime to be stored in the zip file

pzfilepath is the path of the file insize the zip file. This can be an arbitrary path, or a partial path relative to the full file path on disk.

For example if you have a file in a folder "c:\folderA\subfolderB\data\filename1.txt", and you want to store the file on the root of the zip file, then pzfilepath will be "filename1.txt"

If you want to store the file in the zip in a "data" folder, then pzfilepath will be "data\filename1.txt"

To make it easier to get a file path relative to a base path, you can use the function _zipgetzfilepath that removes a base path from a full path.

pfilecomment is optional

pfiletime is optional, if no datetime is provided, the actual last modified time of the file will be used.


_zipaddblob(pblobdata, pzfilepath, [pfilecomment], [pfiletime])

Simmilar to _zipaddfile but to save arbitrary strings to a file in the zip file.


_zipclose(zipfilename, [pzipfilecomment], [puselzma])

zipfilename Name of the zip file

pzipfilecomment Adds a comment to the zip file

puselzma If .t., uses LZMA instead of zlib's deflate as the compression method.


How it works:

_zipopen just creates a temporary cursor.

_zipaddfile and _zipaddblob just add records to this cursor. When you use _zipaddblob, the actual blobdata is saved in a memo binary field in the cursor.

_zlipclose is where all the actual work is done. A zip object is instantiated that manages each file to be added to the zip file. The temporary cursor is scanned, and for each record a local file header is created and written to the zip file, then the actual compressed data is written, then a data descriptor, the central file header is saved on the cursor. After writing all the files, the cursor is scanned again and all the central file headers are written to the zip file, then a end of central directory record.

_zipreport(pzipfile)

creates a report with the same name as the zip file and a txt extension. Reports on the internal structure of the zip file. I used it for testing that the zip functions work as intended.


There are many other functions available. Some of them may be work in progress. The zip creation functions do work.