Thursday, September 06, 2007

VFPCompression Update

This update contains numerous fixes (unfortunately I didn't keep track, I just fixed anything and everything anyone mentioned to me). The library now allows the use of UNC paths, and it also contains a new callback/event feature that allows a user-defined function/procedure/method to be hooked into the Zip and Unzip routines. In so doing the developer can monitor open, close, and even the number of bytes being read or written as the zip functions are called (see ZipCallback in the documentation below).

Here's the customary download link, some sample code for using the new callback feature and the library in general, and the library documentation...

VFP Compression Update:

VFPCompression FLL Download (35 KB approx.)


VFP Compression Event\Callback Sample Code:

SET LIBRARY TO LOCFILE("vfpcompression.fll")
SET DEFAULT TO "C:\Temp"
ZipCallback("MyCallback()") && Start Event Handling - Any Function/Procedure/Method (in scope of course)
?ZipOpen("Test.zip", "C:\MyFolder\", .F.) && create zip file
?ZipFile("C:\MyFolder\MyFile.txt", .F.) && compress file into zip
?ZipClose() && done zipping
?UnzipQuick("C:\MyFolder\Test.zip", "C:\") && unzip contents of Test.zip to C:\
ZipCallback("") && Stop Event Handling
SET LIBRARY TO

*****************************
FUNCTION MyCallback()
*****************************
    *!* Variables below are created on the fly
    *!* by the FLL when the ZipCallback feature is used
    
    *!* Depends on the value of nZipEvent
    ?cZipObjectName && Name of Zip, File, or Folder being processed
    
    *!* Events that fire MyCallback
    *!* 0 = Open Zip
    *!* 1 = Start Zip/Unzip of File
    *!* 2 = Read/Write File (nZipBytes will contain value of bytes read for event)
    *!* 3 - End Zip/Unzip of File
    *!* 4 - Folder Opened
    *!* 5 - Close Zip
    ?nZipEvent
    
    *!* Number of Bytes read (Event 3)
    ?nZipBytes

ENDFUNC


VFP Compression General Sample Code:

*!* Example 1
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipFileQuick("C:\MyFile.txt")
?ZipFileQuick("C:\MyFile.txt", "MyPassword")
SET LIBRARY TO

*!* Example 2
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipFolderQuick("C:\MyFolder")
?ZipFolderQuick("C:\MyFolder2", .T., "MyPassword")
?ZipFolderQuick("C:\MyFolder2", .F., "MyPassword")
SET LIBRARY TO

*!* Example 3
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?UnzipQuick("C:\MyFile.zip", "C:\")
?UnzipQuick("C:\MyFolder.zip", "C:\", .T.)
?UnzipQuick("C:\MyFolder.zip", "C:\", .F., "MyPassword")
SET LIBRARY TO

*!* Example 4
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipOpen("MyZipFile.zip", "C:\", .F.)
?ZipFile("C:\SomeFile.txt", .F.)
?ZipFile("C:\AnotherFile.txt", .F., "MyPassword")
?ZipClose()
SET LIBRARY TO

*!* Example 5
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?UnzipQuick("C:\MyZipFile.zip","C:\",.F.)
?UnzipQuick("C:\MyZipFile.zip","C:\",.F., "MyPassword")
SET LIBRARY TO

*!* Example 6
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipOpen("C:\MyZipFile.zip")
*!* ?ZipOpen("MyZipFile.zip", "C:\", .F.)
?ZipFolder("C:\MyFolder\", .F.) && trailing backslash is optional
?ZipFolder("C:\AnotherFolder", .F., "MyPassword")
?ZipClose()
SET LIBRARY TO

*!* Example 7
SET LIBRARY TO LOCFILE("vfpcompression.fll")
CLEAR
lcOriginal = REPLICATE("Visual FoxPro Rocks!",100)
?"Original Length: " + TRANSFORM(LEN(lcOriginal))
?
lcCompressed = ZipString(lcOriginal)
?"Compressed: " + lcCompressed
?"Compressed Length: " + TRANSFORM(LEN(lcCompressed))
?
?"Length Savings: " + TRANSFORM(LEN(lcOriginal) - LEN(lcCompressed)) + " bytes"
?
lcUncompressed = UnzipString(lcCompressed)
*!* ?"Uncompressed: " + lcUncompressed
?"Uncompressed Length: " + TRANSFORM(LEN(lcUncompressed))
?"Equals Original: " + IIF(lcUncompressed == lcOriginal, "YES", "NO")
IF !(lcUncompressed == lcOriginal)
EXIT
ENDIF
SET LIBRARY TO

*!* Example 8
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipOpen("MyZip.zip", "C:\", .F.)
?ZipFile("C:\MyFile1.txt", .F., "MyPassword1") && passwords for files can be different
?ZipFile("C:\MyFile2.txt", .F., "MyPassword2") && passwords for files can be different
?ZipFile("C:\MyFile3.txt", .F.) && And some files can not be given a password
*!* could zip other files and folders here before close
?ZipClose()
SET LIBRARY TO


VFP Compression Documenation:

Function ZipString()

Signature: ZipString(cString[, nLevel])

Parameters:

cString - The character string you wish to compress

nLevel - The compression level to use which is 1 through 9 (1 is the fastest, while 9 is the best compression). The default value for this parameter is 6.

Return Value:

Character Data - the compressed version of cString.

Remarks:

This function is particularly useful in a client-server application given that strings of data (such as memo fields, character fields, and xml) can be compressed before sending them across the network and then extracted at the other end (using UnzipString).


Function ZipFileQuick()

Signature: ZipFileQuick(cFileName, cPassword)

Parameters:

cFileName - The fully qualified file name (full path) of the file you wish to have compressed.

cPassword - The password you wish to protect the zipped file with.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

The zip file that this function creates will have the same file name as cFileName, with the extension as ".zip".


Function ZipFolderQuick()

Signature: ZipFileQuick(cFolderName[, lIgnorePaths[, cPassword)

Parameters:

cFolderName - The full path to the folder you wish to have zipped.

cPassword - The password you wish to protect the zipped files with.

lIgnorePath - If you wish to ignore the relative path of the file into the zip file that is being created you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative path will be respected.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

The zipfile that this function creates will have the same file name as cFolderName, with the extension as ".zip".


Function ZipOpen()

Signature: ZipOpen(cZipFileName[,cFolderName[,lAppend]])

Parameters:

cZipFileName - The file name or full path of the zip file you wish to create.

cFolderName - The full path of the folder in which you want cZipFileName created.

lAppend - If the zip file you are compressing to exists you can choose to append to it by passing .T. to this parameter. Defaults to .F..

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

ZipOpen() is used in conjunction with the matching ZipClose(). The usual series of function calls would consist of creating/opening the zip file using ZipOpen, zipping files and/or folders using ZipFile/ZipFileRelative/ZipFolder, and then closing the zip file using ZipClose.


Function ZipClose()

Signature: ZipClose()

Parameters: None

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

ZipClose() must be called after issuing a ZipOpen(). The usual series of function calls would consist of creating/opening the zip file using ZipOpen, zipping files and/or folders using ZipFile/ZipFileRelative/ZipFolder, and then closing the zip file using ZipClose.


Function ZipFile()

Signature: ZipFile(cFileName[,lIgnorePath[,cPassword]])

Parameters:

cFileName - The file name or full path of the file you wish to compress.

lIgnorePath - If you wish to ignore the relative path of the file into the zip file that is being created you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative path will be respected.

cPassword - The password you wish to protect the zipped file with.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

ZipFile() is used between calls to ZipOpen() and ZipClose(). The usual series of function calls would consist of creating/opening the zip file using ZipOpen, zipping files and/or folders using ZipFile/ZipFileRelative/ZipFolder, and then closing the zip file using ZipClose.

The cPassword is usually the same for all files within a zip, however it does not need to be the same. Different passwords can be specified for different files and you can even selectively password protect files within the zip.


Function ZipFileRelative()

Signature: ZipFileRelative(cFileName[,cRelativePath[, cPassword]])

Parameters:

cFileName - The file name or full path of the file you wish to compress.

cRelativePath - The relative path you wish to have saved in the zip for this file. This allows you to set up the structure (relative paths) in the zip different from the actual relative paths of the files you are compressing.

cPassword - The password you wish to protect the zipped file with.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

ZipFileRelative() is used between calls to ZipOpen() and ZipClose(). The usual series of function calls would consist of creating/opening the zip file using ZipOpen, zipping files and/or folders using ZipFile/ZipFileRelative/ZipFolder, and then closing the zip file using ZipClose.

The cPassword is usually the same for all files within a zip, however it does not need to be the same. Different passwords can be specified for different files and you can even selectively password protect files within the zip.


Function ZipFolder()

Signature: ZipFolder(cFolderName[,lIgnorePaths[, cPassword])

Parameters:

cFolderName - The full path to the folder you wish to compress.

lIgnorePaths - If you wish to ignore the relative path of the folder into the zip file that is being created you would pass .T. for this parameter. The default value for this parameter is .F. which means that paths will be respected.

cPassword - The password you wish to protect the zipped file with.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

ZipFolder() is used between calls to ZipOpen() and ZipClose(). The usual series of function calls would consist of creating/opening the zip file using ZipOpen, zipping files and/or folders using ZipFile/ZipFileRelative/ZipFolder, and then closing the zip file using ZipClose.


Function UnzipString()

Signature: UnzipString(cString)

Parameters:

cString - The compressed string you wish to uncompress.

Return Value:

Character Data - the extracted version of cString.

Remarks:

The string to be extracted must have been compressed with the ZipString() function or other compression function that is compatible with the compress or compress2 functions in zlib.


Function UnzipQuick()

Signature: UnzipQuick(cZipFileName, cOutputFolderName[, lIgnorePaths[, cPassword]])

Parameters:

cZipFileName - The fully qualified file name (full path) of the zip file you wish to have extracted.

cOutputFolderName - The full path to the folder you wish to extract the contents of the zip to.

cPassword - The password to use when unzipping the file.

lIgnorePaths - If you wish to ignore the relative paths that are contained in the zip file you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative paths will be respected.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

The file and folders in the zip file will be extracted into the same folder as the cZipFileName resides in.


Function UnzipOpen()

Signature: UnzipOpen(cZipFileName)

Parameters:

cZipFileName - The file name or full path of the zip file you wish to uncompress.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipOpen() is used in conjunction with the matching UnzipClose(). The usual series of function calls would consist of opening the zip file using UnzipOpen, uncompressing files and/or folders using Unzip/UnzipTo/UnzipByIndex/UnzipFile, and then closing the zip file using UnzipClose.


Function UnzipClose()

Signature: UnzipClose()

Parameters: None

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipClose() must be called after issuing an UnzipOpen(). The usual series of function calls would consist of opening the zip file using UnzipOpen, uncompressing files and/or folders using Unzip/UnzipTo/UnzipByIndex/UnzipFile, and then closing the zip file using UnzipClose.


Function Unzip()

Signature: Unzip(lIgnorePaths[, cPassword])

Parameters:

lIgnorePaths - If you wish to ignore the relative paths that are contained in the zip file you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative paths will be respected.

cPassword - The password to use when unzipping the file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

Unzip() is used between calls to UnzipOpen() and UnzipClose() to uncompress the entire zip file. The files and folders contained in the zip file will be extracted to the same folder as the zip file resides in unless a call to UnzipSetFolder() has been previously issued. The usual series of function calls would consist of opening the zip file using UnzipOpen, uncompressing files and/or folders using Unzip/UnzipTo/UnzipByIndex/UnzipFile, and then closing the zip file using UnzipClose.


Function UnzipTo()

Signature: UnzipTo(cOutputFolderName[, lIgnorePaths[, cPassword]])

Parameters:

cOutputFolderName - The folder into which the zip file contents should be extracted.

lIgnorePaths - If you wish to ignore the relative paths that are contained in the zip file you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative paths will be respected.

cPassword - The password to use when unzipping the file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipTo() is used between calls to UnzipOpen() and UnzipClose(). The functionality of this is similar to calling UnzipSetFolder() and then Unzip(). The usual series of function calls would consist of opening the zip file using UnzipOpen, uncompressing files and/or folders using Unzip/UnzipTo/UnzipByIndex/UnzipFile, and then closing the zip file using UnzipClose.


Function UnzipFile()

Signature: UnzipFile(cOutputFolderName[, lIgnorePaths[, cPassword]])

Parameters:

cOutputFolderName - The folder into which the current file (cotained in the zip) should be extracted.

lIgnorePaths - If you wish to ignore the relative path of the current file you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative path will be respected.

cPassword - The password to use when unzipping the file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipFile() is used between calls to UnzipOpen() and UnzipClose() to extract the currently selected file contained in the zip file. UnzipFile() is used in conjunction with the UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions. You can think of the contents of a zip file as records in a table. In this sense UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions are used to move the record pointer and the UnzipFile function is used to extract the file that the record pointer is currently on.

The cPassword is usually the same for all files within a zip, however it does not need to be the same. Just keep in mind that passwords can be specified for different files within a zip and when you are unzipping such an archive you will need to change the cPassword accordingly.


Function UnzipByIndex()

Signature: UnzipByIndex(nIndex[, cOutputFolderName[,lIgnorePaths, cPassword]]])

Parameters:

nIndex - The index number of the file to be extracted.

cOutputFolderName - The folder into which the zip file contents should be extracted.

lIgnorePaths - If you wish to ignore the relative path for this file that is contained in the zip file you would pass .T. for this parameter. The default value for this parameter is .F. which means that the relative path will be respected.

cPassword - The password to use when unzipping the file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipByIndex() is used between calls to UnzipOpen() and UnzipClose() to extract a file by the position (index) it holds in the zip file. UnzipByIndex() is used in conjunction with the UnzipFileCount function. You can think of the contents of a zip file as records in a table. In this sense UnzipFileCount would give you the record count for the table and the UnzipByIndex function be used to extract a particular file by record number.

The cPassword is usually the same for all files within a zip, however it does not need to be the same. Just keep in mind that passwords can be specified for different files within a zip and when you are unzipping such an archive you will need to change the cPassword accordingly.


Function UnzipFileCount()

Signature: UnzipFileCount()

Parameters: None

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipFileCount() is used between calls to UnzipOpen() and UnzipClose() to retrieve the number of files that are contained in the zip file. It does not actually extract anything. UnzipFileCount() is used in conjunction with the UnzipByIndex function. You can think of the contents of a zip file as records in a table. In this sense UnzipFileCount would give you the record count for the table and the UnzipByIndex function be used to extract a particular file by record number.


Function UnzipSetFolder()

Signature: UnzipSetFolder(cOutputFolderName)

Parameters:

cOutputFolderName - The folder into which the zip file contents should be extracted.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipSetFolder() is used between calls to UnzipOpen() and UnzipClose() to set the output folder for extracted zip contents. It does not actually extract anything. The usual series of function calls would consist of opening the zip file using UnzipOpen, calling UnzipSetFolder to set the output folder, uncompressing files and/or folders using Unzip/UnzipTo/UnzipByIndex/UnzipFile, and then closing the zip file using UnzipClose.


Function UnzipGotoTopFile()

Signature: UnzipGotoTopFile([cExtension])

Parameters:

cExtension - The file extension to use as a filter for file type. All other file types will be ignored and only the first file of the type specified will be selected in the zip file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipGotoTopFile() is used between calls to UnzipOpen() and UnzipClose() to select a particular file in the contents of the open zip file. UnzipGotoTopFile() is used in conjunction with the UnzipFile function to extract a particular file from the zip. By using the cExtension optional parameter you can select the first record of a particular file type. You can think of the contents of a zip file as records in a table. In this sense UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions are used to move the record pointer and the UnzipFile function is used to extract the file that the record pointer is currently on.


Function UnzipGotoNextFile()

Signature: UnzipGotoNextFile([cExtension])

Parameters:

cExtension - The file extension to use as a filter for file type. All other file types will be ignored and only the next file of the type specified will be selected in the zip file.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipGotoNextFile() is used between calls to UnzipOpen() and UnzipClose() to select a particular file in the contents of the open zip file. UnzipGotoNextFile() is used in conjunction with the UnzipFile function to extract a particular file from the zip. By using the cExtension optional parameter you can select the next record of a particular file type. You can think of the contents of a zip file as records in a table. In this sense UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions are used to move the record pointer and the UnzipFile function is used to extract the file that the record pointer is currently on.


Function UnzipGotoFileByName()

Signature: UnzipGotoFileByName(cFileName[, lIgnoreFilePath])

Parameters:

cFileName - The file name of the file you wish to select in the zip file contents. You can specify a relative path as well to narrow down the search.

lIgnoreFilePath - If you wish to just find a file of a particular name in the zip file you can pass .T. for this parameter and the relative path of the file will be ignored. The first matching file of the name specified in cFileName will be selected in the zip contents.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipGotoFileByName() is used between calls to UnzipOpen() and UnzipClose() to select a particular file in the contents of the open zip file by file name and/or relative path. UnzipGotoFileByName() is used in conjunction with the UnzipFile function to extract a particular file from the open zip file. You can think of the contents of a zip file as records in a table. In this sense UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions are used to move the record pointer and the UnzipFile function is used to extract the file that the record pointer is currently on.


Function UnzipGotoFileByIndex()

Signature: UnzipGotoFileByIndex([nIndex])

Parameters:

nIndex - The index number of the file to be selected.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Remarks:

UnzipGotoFileByIndex() is used between calls to UnzipOpen() and UnzipClose() to select a particular file by the position it physically holds in the contents of the open zip file. UnzipGotoFileByIndex() is used in conjunction with the UnzipFile function to extract a particular file from the zip file contents. You can think of the contents of a zip file as records in a table. In this sense UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions are used to move the record pointer and the UnzipFile function is used to extract the file that the record pointer is currently on.


Function UnzipAFileInfoByIndex()

Signature: UnzipAFileInfoByIndex(cArrayName, nIndex)

Parameters:

cArrayName - Name of the VFP array to be created with file information in it.

nIndex - The index number of the file you want to return information about.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Creates an array with 13 rows (elements) in it. The rows contain various pieces of information regarding the file that is held in the zip file at nIndex. The following table describes the contents and data type of each row in the array:

Row Array Content Data Type
1 File Name Character
2 Comment Character
3 Version Numeric
4 Version Needed Numeric
5 Flags Numeric
6 Compression Method Numeric
7 DOS Date Datetime
8 CRC Numeric
9 Compressed Size Numeric
10 Uncompressed Size Numeric
11 Internal Attribute Numeric
12 External Attribute Numeric
13 Folder Logical

Remarks:

The array that is created will have whatever name was specified by cArrayName. Should the array already exist it will release it and recreate it. UnzipAFileInfoByIndex() is used between calls to UnzipOpen() and UnzipClose() to show information about a particular file. The file is referred to by the position it physically holds in the contents of the open zip file. You can think of the contents of a zip file as records in a table. In this sense the UnzipAFileInfoByIndex function is used to refer to and retrieve information about a particular record number in the zip file.


Function UnzipAFileInfo()

Signature: UnzipAFileInfo(cArrayName)

Parameters:

cArrayName - Name of the VFP array to be created with file information in it.

Return Value:

Logical - returns .T. if successful or .F. if the operation has failed.

Creates an array with 13 rows (elements) in it. The rows contain various pieces of information regarding the currently selected file in the zip. The following table describes the contents and data type of each row in the array:

Row Array Content Data Type
1 File Name Character
2 Comment Character
3 Version Numeric
4 Version Needed Numeric
5 Flags Numeric
6 Compression Method Numeric
7 DOS Date Datetime
8 CRC Numeric
9 Compressed Size Numeric
10 Uncompressed Size Numeric
11 Internal Attribute Numeric
12 External Attribute Numeric
13 Folder Logical

Remarks:

The array that is created will have whatever name was specified by cArrayName. Should the array already exist it will release it and recreate it. UnzipAFileInfo() is used between calls to UnzipOpen() and UnzipClose() to show information about a particular file. Use the UnzipAFileInfo function in conjunction with UnzipGotoTopFile, UnzipGotoNextFile, UnzipGotoFileByName, and UnzipGotoFileByIndex functions to return information regarding a particular file contained in the open zip file. You can think of the contents of a zip file as records in a table. In this sense the UnzipAFileInfo function is used to refer to and retrieve information about the record that the record pointer is currently on within the zip file.


Function ZipCallback()

Signature: ZipCallback(cFunction)

Parameters:

cFunction - A string denoting a function, procedure, or method that you want fired whenever a zip event occurs, such as "MyCallback()".

Return Value: None

Events:

When one of the following zip events occurs the function/procedure/method specified by the cFunction parameter will be called. cZipObjectName, nZipEvent, and nZipBytes are private variables created on-the-fly by the FLL. They will contain the values specified in the table below.

Event Description cZipObjectName (character) nZipEvent (numeric) nZipBytes (numeric)
Zip Opened Name and path of zip file 0 N/A
Zip/Unzip File Start Name and path of file being zipped/unzipped 1 N/A
Zip Read or Unzip Write Name and path of file being zipped/unzipped 2 Number of bytes currently being read or written
Zip/Unzip File End Name and path of file being zipped/unzipped 3 N/A
Zip/Unzip Folder Opened Name and path of folder being zipped/unzipped 4 N/A
Zip Closed Name and path of zip file 5 N/A

Remarks:

Event handling is started as soon as you call ZipCallback and pass it the name of a function, procedure, or object method. ZipCallback provides a way for you to hook into the internal events happening inside of the VFPCompression FLL. nZipBytes reports the number of bytes currently being read during zip (2048 bytes at a time) or written during unzip (4096 bytes at a time) of an individual file. In order to turn off event handling simply call the ZipCallback with an empty length string, such as ZipCallback("").

Thursday, September 06, 2007 11:57:16 PM (Central Daylight Time, UTC-05:00)  #    Comments [15]
Friday, September 07, 2007 8:53:05 AM (Central Daylight Time, UTC-05:00)
Hi Craig,

Thank's for your great Library,

It's very easy to use in VFP.

Thank's
Olivier
Friday, September 07, 2007 1:49:13 PM (Central Daylight Time, UTC-05:00)
Cool, thanks again for this Craig.

Monday, September 10, 2007 10:56:34 AM (Central Daylight Time, UTC-05:00)
Hi! I like your library a lot!
But I have a question: I wanna zip only some types of files in a folder (for example "C:\MyFolder\*.txt"). Is there any way I can do this with your library? Can u add this feature? I will try to do it some other way if not possible, but it would help me a lot if I could do this directly from your library.

Thank a lot!
Micky
Tuesday, September 11, 2007 3:50:39 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

I was trying to use the password feature when zipping an entire folder using the following syntax:

IF !ZipFolderQuick("C:\MyFolder", .F., "testing")
WAIT WINDOW "Zip failed"
ENDIF

While it does create the zip file named MyFolder.Zip on the root of C, it is not password protected. At least I don't think it is because if I just double click it from Windows Explorer, it opens up. I was expecting a prompt to enter "testing" before it would show the contents.

Did I miss something here?

Thanks,

Mike
MikeS
Friday, September 14, 2007 10:33:35 AM (Central Daylight Time, UTC-05:00)
micky,
Adding a feature that allows for a file mask/wildcard matching is a good suggestion, however the library does not provide for this now. That having been said, you could use Sys(2000) and a Do While loop to accomplish this pretty easily in VFP.

Mike,
I'm assuming by "show the contents" that you mean you could see the folder/file names within the zip even though the files were encrypted? This is standard zip compression as far as I know. While the files themselves are encrypted and require the password to extract them properly, the zip will still show the folder/file names when viewing the contents of the zip. I've looked at a number of zipping utilities and they all appear to work that way. The only type of zip that appears to request the password before anything can be seen is a self-extracting exe.
Tuesday, September 18, 2007 9:36:09 AM (Central Daylight Time, UTC-05:00)
Hi Craig!

The library is very nice.

I have a cosmetic problem, the callback function is not as usefull as i thinked first. Mainly in the zipfolder, zipfilequick etc... (folder and quick functions) i can't get the expected progress bar.
Let's see the situation:
if i unzip(zip) an archive with many files in it, then i can't get a progress indicator about the whole progress, only file by file which is not usefull because i can't show how the whole progress going.At unzip i don't know at the start how many files will be in the zip so i can't count it manually.

my solution:another private variable in the mycallback, like nZipTotalBytes , which contains the actual position in the whole .zip file when the event occurs.

I hope i clearly explained what i want to say :-)
Laky
Monday, September 24, 2007 1:57:54 PM (Central Daylight Time, UTC-05:00)
Craig,

Great library! Is there any way to get error information when a zipfile call returns .F.? I'm getting a .F. when trying to zip a file and can't figure out why.
Phil
Friday, October 05, 2007 5:31:22 AM (Central Daylight Time, UTC-05:00)
Set Library To c:\vfpzip\vfpcompression.fll
?zipopen('c:\temp.zip')
?ZipFile('C:\VFPZIP\images\FOLDER7.PNG',.f.) Not working
?ZipFile('C:\VFPZIP\images\readme.txt',.f.) Working
?ZipFile('C:\VFPZIP\images\readme.txt',.t.) Working

i think pictures are not zipped,so please you can also try like above command
Arjun Bagojikop
Monday, October 08, 2007 10:39:01 AM (Central Daylight Time, UTC-05:00)
Hi,

i've a problem, when i save the zip file in a directory, with the option .f. in zipfile(), the library return error. If the zip file is in the c:\ directory return .t., Why ???

EXAMPLE 1 :
? zipopen("temp.zip", "c:\temp",.F.)
? ZipFile("C:\MyFolder\MyFile.txt", .F.) &&& RETURN .f.

example 2:
? zipopen("temp.zip", "c:\",.F.)
? ZipFile("C:\MyFolder\MyFile.txt", .F.) &&& RETURN .t.

example 3:
? zipopen("temp.zip", "c:\temp",.F.)
? ZipFile("C:\MyFolder\MyFile.txt", .T.) &&& RETURN .f.


why example 2 don't work ?

Raffaele Viglione
Raffaele Viglione
Tuesday, October 23, 2007 3:12:39 PM (Central Daylight Time, UTC-05:00)
Hey, Craig - this is really cool but the one thing it does NOT do is zip up a file that is currently in use.

I know winzip allows you to do this - is there a setting in the general ZLIB that allows you to do that? That would be very useful.
Thursday, November 15, 2007 4:38:57 PM (Central Standard Time, UTC-06:00)
Hi Craig.

Great piece of code.

Your documentation on UnzipQuick() has a minor issue -- cOutputFolderName is not marked as optional (but it both works that way and is indicated as being that way elsewhere in the docs). It's a little confusing. Just thought you'd like to know.

Thanks!
Peter Crabtree
Wednesday, November 21, 2007 11:01:15 AM (Central Standard Time, UTC-06:00)
Hi Craig,

Wonderful job!

(I'm not a native English speaker, but I'll try to explain my idea :)

Add the possibility that the callback function returns a logical value. This way, it would provide a way to abort the work in progress.

ZipCallback("MyCallback()")
ZipOpen(...)
ZipFolder(...)
...

function MyCallback()
local llContinue

llContinue = .T.
&& Display some info about the work in progress
...
if some_condition
llContinue = .F. && Abort !
endif

return llContinue
Serge
Friday, January 18, 2008 3:47:15 PM (Central Standard Time, UTC-06:00)
Hi Craig,

This is a wonderful tool, it will enable me to auto backup some of our customers data as they never do when they need to do (as i bet you know!)

One issue i've found though is that like 'Raffaele Viglione' has reported above is that if you set the zip file to be in a folder that's not a parent of the folder(s) you're zipping it fails.

Ie.

My Zip file is 'c:\temp\testzip.zip' and my folder to zip it 'c:\temp\unitytest' that will work
My Zip file is 'c:\temp\testzip.zip' and my folder to zip it 'c:\tempcopy\unitytest' that will NOT work
My Zip file is 'c:\testzip.zip' and my folder to zip it 'c:\tempcopy\unitytest' that will work

So it seems to me that even though the ZipOpen will create the zip for you, the ZipFolder/ZipFile doesn't find the required files unless their in a child folder.

Cheers
Colin
Colin Richardson
Thursday, February 21, 2008 2:37:45 PM (Central Standard Time, UTC-06:00)
Hi Craig

Excellent work as ever!

Just a comment to say if you add DOEVENTS into the callback function/procedure/method together with an appropriate object property, MESSAGEBOX() question etc, you can enable the user to instantly cancel out of the entire operation.

Chris
Tuesday, March 11, 2008 1:26:58 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

this library is one of the very useful things for FoxPro we all missed in the past!
Thank's a lot for this library!

But there is still a problem in the ZipOpen function, if you use the additional foldername option and the folder is within the path that should be compressed.

e.g.: Zip a folder called C:\PROJECT and in this folder is a folder named BACKUP, in which the zip-file should be stored. That is not possible.

In that case, the ZipFile will be created, but nothing will be stored inside!
In the moment I have to create the zip-file in a, lets say, 'outside folder' and after successfull adding into the archive, I have to copy the zip-file to the correct destination.

And also it would be neccessary to have an exclude function.

That would be a very great advantage within the compression library.

Brgds,
Martin
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):


 

Archive

<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456