Harbour Reference Guide

hb_GetZipComment()Source code  |  | Improve this doc

Return the comment of an zip file
Syntax
hb_GetZipComment( <szFile> ) → <szComment>
Arguments
szFile File to get the comment from
Returns
szComment The comment that was stored in szFile
Description
This function receives a valid zip file name as parameter, and returns the global comment stored within.
Examples
? "The comment in test.zip is:", hb_GetZipComment( "test.zip" )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_SetBuffer()Source code  |  | Improve this doc

Syntax
hb_SetBuffer( [<nWriteBuffer>], [<nExtractBuffer>], [<nReadBuffer>] ) → NIL
Arguments
nWriteBuffer The size of the write buffer.
nExtractBuffer The size of the extract buffer.
nReadBuffer The size of the read buffer.
Returns
NIL This function always returns NIL.
Description

This function set the size of the internal buffers for write/extract/read operation.

If the size of the buffer is smaller then the default, the function will automatically use the default values, which are 65535/16384/32768 respectively.

This function be called before any of the compression/decompression functions.

Examples
hb_SetBuffer( 100000, 115214, 65242 )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_SetDiskZip()Source code  |  | Improve this doc

Set a codeblock for disk changes
Syntax
hb_SetDiskZip( <bBlock> ) → .T.
Arguments
bBlock a codeblock that contains an function that will be performed when the need of changing disk are need.
Returns
It always returns True
Description

This function will set a codeblock that will be evaluated every time that an change-disk event is necessary. bBlock receives nDisk as a codeblock param that corresponds to the diskette number to be processed.

Set this function before opening archives that are in removable media. This block will be released, when the caller finish it job.

Examples
hb_SetDiskZip( {| nDisk | Alert( "Please insert disk no " + hb_ntos( nDisk ) ) } )
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_SetZipComment()Source code  |  | Improve this doc

Set an Zip archive Comment
Syntax
hb_SetZipComment( <cComment> ) → NIL
Arguments
cComment Comment to add to the zip archive
Returns
NIL this function always return NIL
Description
This function stored an global comment to an zip archive. It should be called before any of the compression functions.
Examples
? hb_SetZipComment( "This is an Test" )
? hb_ZipFile( "test.zip", { "test.xml", "test.ini" } )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_UnzipFile()Source code  |  | Improve this doc

Unzip a compressed file
Syntax
hb_UnzipFile( <cFile>, <bBlock>, <lWithPath>, <cPassword>, <cPath>,
              <cFile> | <aFile>, <pFileProgress> ) → lCompress
Arguments
cFile Name of the zip file to extract
bBlock Codeblock to execute while extracting
lWithPath Toggle to create directory if needed
cPassword Password to use to extract files
cPath Path to extract the files to - mandatory
cFile | aFiles A File or Array of files to extract - mandatory
pFileProgress Codeblock for File Progress
Returns
lCompress .T. if all file was successfully restored, otherwise .F.
Description

This function restores all files contained inside the cFile. If the extension is omitted, .zip will be assumed. If a file already exists, it will be overwritten.

If bBlock is used, every time the file is opened to compress it will evaluate bBlock. Parameters of bBlock are cFile and nPos.

The cPath is a mandatory parameter. Set to ./ to extract to the current directory.

If cFile or aFiles are not provided, no files will be extracted! Make sure you provide the file or files you want extracted.

If pFileProgress is used, a codeblock is evaluated, showing the total of that file has being processed. The codeblock must be defined as: {| nPos, nTotal | GaugeUpdate( aGauge1, nPos / nTotal ) }

Examples
LOCAL aExtract := hb_GetFilesInZip( "test.zip" )  // extract all files in zip

IF hb_UnzipFile( "test.zip",,,, hb_DirSepToOS( "./" ), aExtract )
   ? "File was successfully extracted"
ENDIF

aExtract := hb_GetFilesInZip( "test2.zip" )  // extract all files in zip
IF hb_UnzipFile( "test2.zip", {| cFile | QOut( cFile ) },,, hb_DirSepToOS( "./" ), aExtract )
   ? "File was successfully extracted"
ENDIF
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_ZipDeleteFiles()Source code  |  | Improve this doc

Delete files from an zip archive
Syntax
hb_ZipDeleteFiles( <cFile>, <cFiletoDelete> | <aFiles> | <nFilePos> ) → lDeleted
Arguments
cFile The name of the zip files from where the files will be deleted
cFiletoDelete An File to be removed
or
aFiles An Array of Files to be removed
or
nFilePos The Position of the file to be removed
Returns
lDeleted If the files are deleted, it will return .T.; otherwise it will return .F. in the following cases: Spanned Archives; the file(s) could not be found in the zip file.
Description
This function removes files from an Zip archive.
Examples
? "has the file zipnew.i been deleted:", iif( hb_ZipDeleteFiles( "test23.zip", "zipnew.i" ), "Yes", "No" )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_ZipFile()Source code  |  | Improve this doc

Create a zip file
Syntax
hb_ZipFile( <cFile>, <cFileToCompress> | <aFiles>, <nLevel>,
<bBlock>, <lOverWrite>, <cPassword>, <lWithPath>, <lWithDrive>,
<pFileProgress> ) → lCompress
Arguments
cFile Name of the zip file to create
cFileToCompress Name of a file to Compress, Drive and/or path can be used
or
aFiles An array containing files to compress, Drive and/or path can be used
nLevel Compression level ranging from 0 to 9
bBlock Codeblock to execute while compressing
lOverWrite Toggle to overwrite the file if exists
cPassword Password to encrypt the files
lWithPath Toggle to store the path or not
lWithDrive Toggle to store the Drive letter and path or not
pFileProgress Codeblock for File Progress
Returns
lCompress .T. if file was create, otherwise .F.
Description

This function creates a zip file named cFile. If the extension is omitted, .zip will be assumed. If the second parameter is a character string, this file will be added to the zip file. If the second parameter is an array, all file names contained in aFiles will be compressed.

If nLevel is used, it determines the compression type where 0 means no compression and 9 means best compression.

If bBlock is used, every time the file is opened to compress it will evaluate bBlock. Parameters of bBlock are cFile and nPos.

If lOverWrite is used, it toggles to overwrite or not the existing file. Default is to overwrite the file, otherwise if lOverWrite is false the new files are added to the cFile.

If cPassword is used, all files that are added to the archive are encrypted with the password.

If lWithPath is used, it tells the path should also be stored with the file name. Default is false.

If lWithDrive is used, it tells that the Drive and path should also be stored with the file name. Default is false.

If pFileProgress is used, a codeblock is evaluated, showing the total of that file has being processed. The codeblock must be defined as: {| nPos, nTotal | GaugeUpdate( aGauge1, nPos / nTotal ) }

Examples
LOCAL aFiles, nLen, aGauge

IF hb_ZipFile( "test.zip", "test.prg" )
   ? "File was successfully created"
ENDIF

IF hb_ZipFile( "test1.zip", { "test.prg", "test.hbp" } )
   ? "File was successfully created"
ENDIF

IF hb_ZipFile( "test2.zip", { "test.prg", "test.hbp" }, 9, {| cFile, nPos | QOut( cFile ) } )
   ? "File was successfully created"
ENDIF

aFiles := { "test.prg", "test.hbp" }
nLen   := Len( aFiles )
hb_ZipFile( "test33.zip", aFiles, 9,,, "hello" )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_ZipFileByPKSpan()Source code  |  | Improve this doc

Create a zip file on removable media
Syntax
hb_ZipFileByPKSpan( <cFile>, <cFileToCompress> | <aFiles>, <nLevel>,
<bBlock>, <lOverWrite>, <cPassword>, <lWithPath>, <lWithDrive>,
<pFileProgress> ) → lCompress
Arguments
cFile Name of the zip file
cFileToCompress Name of a file to Compress, Drive and/or path can be used
or
aFiles An array containing files to compress, Drive and/or path can be used
nLevel Compression level ranging from 0 to 9
bBlock Codeblock to execute while compressing
lOverWrite Toggle to overwrite the file if exists
cPassword Password to encrypt the files
lWithPath Toggle to store the path or not
lWithDrive Toggle to store the Drive letter and path or not
pFileProgress Codeblock for File Progress
Returns
lCompress .T. if file was create, otherwise .F.
Description

This function creates a zip file named cFile. If the extension is omitted, .zip will be assumed. If the second parameter is a character string, this file will be added to the zip file. If the second parameter is an array, all file names contained in aFiles will be compressed. Also, the use of this function is for creating backup in removable media like an floppy drive/zip drive.

If nLevel is used, it determines the compression type where 0 means no compression and 9 means best compression.

If bBlock is used, every time the file is opened to compress it will evaluate bBlock. Parameters of bBlock are cFile and nPos.

If lOverWrite is used, it toggles to overwrite or not the existing file. Default is to overwrite the file, otherwise if lOverWrite is false the new files are added to the cFile.

If cPassword is used, all files that are added to the archive are encrypted with the password.

If lWithPath is used, it tells that the path should also be stored with the file name. Default is false.

If lWithDrive is used, it tells that the Drive and path should also be stored with the file name. Default is false.

If pFileProgress is used, a codeblock is evaluated, showing the total of that file has being processed. The codeblock must be defined as: {| nPos, nTotal | GaugeUpdate( aGauge1, nPos / nTotal ) }

Before calling this function, set a change-disk codeblock by calling the hb_SetDiskZip().

Examples
LOCAL aFiles, nLen, aGauge

hb_SetDiskZip( {| nDisk | Alert( "Please insert disk no " + hb_ntos( nDisk ) ) } )

IF hb_ZipFileByPKSpan( "test.zip", "test.prg" )
   ? "File was successfully created"
ENDIF

IF hb_ZipFileByPKSpan( "test1.zip", { "test.prg", "test.hbp" } )
   ? "File was successfully created"
ENDIF

IF hb_ZipFileByPKSpan( "test2.zip", { "test.prg", "test.hbp" }, 9, {| cFile, nPos | QOut( cFile ) } )
   ? "File was successfully created"
ENDIF

aFiles := { "test.prg", "test.hbp" }
nLen   := Len( aFiles )
hb_ZipFileByPKSpan( "test33.zip", aFiles, 9,,, "hello" )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_ZipFileByTDSpan()Source code  |  | Improve this doc

Create a zip file
Syntax
hb_ZipFileByTDSpan( <cFile>, <cFileToCompress> | <aFiles>, <nLevel>,
<bBlock>, <lOverWrite>, <cPassword>, <iSize>, <lWithPath>, <lWithDrive>,
<pFileProgress>) → lCompress
Arguments
cFile Name of the zip file
cFileToCompress Name of a file to Compress, Drive and/or path can be used
or
aFiles An array containing files to compress, Drive and/or path can be used
nLevel Compression level ranging from 0 to 9
bBlock Codeblock to execute while compressing
lOverWrite Toggle to overwrite the file if exists
cPassword Password to encrypt the files
iSize Size of the archive, in bytes. Default is 1457664 bytes
lWithPath Toggle to store the path or not
lWithDrive Toggle to store the Drive letter and path or not
pFileProgress Codeblock for File Progress
Returns
lCompress .T. if file was create, otherwise .F.
Description

This function creates a zip file named cFile. If the extension is omitted, .zip will be assumed. If the second parameter is a character string, this file will be added to the zip file. If the second parameter is an array, all file names contained in aFiles will be compressed.

If nLevel is used, it determines the compression type where 0 means no compression and 9 means best compression.

If bBlock is used, every time the file is opened to compress it will evaluate bBlock. Parameters of bBlock are cFile and nPos.

If lOverWrite is used, it toggles to overwrite or not the existing file. Default is to overwrite the file, otherwise if lOverWrite is false the new files are added to the cFile.

If lWithPath is used, it tells that the path should also be stored with the file name. Default is false.

If lWithDrive is used, it tells that the Drive and path should also be stored with the file name. Default is false.

If pFileProgress is used, a codeblock is evaluated, showing the total of that file has being processed. The codeblock must be defined as: {| nPos, nTotal | GaugeUpdate( aGauge1, nPos / nTotal ) }

Examples
LOCAL aFiles, nLen, aGauge

IF hb_ZipFileByTDSpan( "test.zip", "test.prg" )
   ? "File was successfully created"
ENDIF

IF hb_ZipFileByTDSpan( "test1.zip", { "test.prg", "test.hbp" } )
   ? "File was successfully created"
ENDIF

IF hb_ZipFileByTDSpan( "test2.zip", { "test.prg", "test.hbp" }, 9, {| cFile, nPos | QOut( cFile ) }, "hello",, 521421 )
   ? "File was successfully created"
ENDIF

aFiles := { "test.prg", "test.hbp" }
hb_ZipFileByTDSpan( "test33.zip", aFiles, 9,,, "hello",, 6585452 )
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions

hb_ZipTestPK()Source code  |  | Improve this doc

Test pkSpanned zip files
Syntax
hb_ZipTestPK( <cFile> ) → nReturnCode
Arguments
cFile File to be tested.
Returns
nReturn A code that tells if the current disk is the last of a pkSpanned disk set.
Description

This function tests if the disk inserted is the last disk of an backup set or not. It will return the follow return code when an error is found

Error code     Meaning
114            Incorrect Disk
103            No Call back was set with hb_ZipTestPK()

Call this function to determine if the disk inserted is the correct one before any other function.

Examples
IF hb_ZipTestPK( "test22.zip" ) == 114
   ? "Invalid Diskette"
ENDIF
Status
Ready
Compliance
Harbour specific
Platforms
Available on all platforms
File
Library is hbziparc
Tag
Zip Functions