TestEntry()
Previous  Top  Next

:TestEntry() - Test a single (File) Entry of the Zip File.

Syntax

:TestEntry(<cEntry> | <nEntry> | <oEntry>,  
          [<lFakeCDRec>]) --> nStatus  

Parameters

The first Parameter can be either a Character String, a Number, or a Central Directory Record Object:  
 
<cEntry>  
<cEntry> specifies the File Name of the Central Directory Record Entry that contains the information for the (File) Entry that should be tested in the Zip File.  

<nEntry>  
<nEntry> specifies the Index Number of the Central Directory Record Entry that contains the information for the (File) Entry that should be tested in the Zip File.  

<oEntry>  
<oEntry> specifies the ZipCentralDirectoryRecord object of the (File) Entry that should be tested in the Zip File.  

<lFakeCDRec>  
<lFakeCDRec> optionally specifies if the given Central Directory Record object is a real record -- rather than an artificial test record that was created from an orphaned Local File Record, just for testing. The default value is .F. (FALSE) and a real, existing Central Directory Record object is assumed.  

Returns

This method returns the (new) Status of the tested (File) Entry. This value is a Bit Mask. If no Bit is set, no Error was found, and the returned value will be Zero (0). Otherwise, the appropriate Bit(s) for each of the found Errors is set. The following Define Constants from the XbZLib.ch file are used for Bits 1 through XBZ_MAX_ERROR_CODES, in addition to XBZ_ENTRY_OK, which means that no Error was found:  
 
Define
Value
or Bit Set

Description
XBZ_ENTRY_OK
0
Local Record and Data are OK (absolute value)
XBZ_CRC_WRONG
(Bit) 1
CRC of Data is wrong
XBZ_NO_CDREC
(Bit) 2
Central Directory Record not Found
XBZ_NO_LFDREC
(Bit) 3
Local File Record (and Data) not Found
XBZ_VER_DIFF
(Bit) 4
Different Version-to-Extract Flags
XBZ_GPFLAG_DIFF
(Bit) 5
Different General Purpose Flags
XBZ_METHOD_DIFF
(Bit) 6
Different Compression Methods
XBZ_FTIME_DIFF
(Bit) 7
Different File Times
XBZ_CRC_DIFF
(Bit) 8
Different CRCs
XBZ_CSIZE_DIFF
(Bit) 9
Different Compressed-Sizes
XBZ_OSIZE_DIFF
(Bit) 10
Different Original (Un-Compressed)-Sizes
XBZ_FNLEN_DIFF
(Bit) 11
Different File Name Lengths
XBZ_FNAME_DIFF
(Bit) 12
Different File Names
XBZ_MAX_ERROR_CODES
12
Number of currently used Error Status Bits (absolute value)
 
 
Bits 4 through 12 are set if the corresponding Fields/Values of the Central Directory and Local File Records differ from each other. The Extra Field and Extra Field Length can differ without this being a problem or Error!  

Description

This method tests the (File) Entry of the given Central Directory Record for existence and consistency with the corresponding Local File Record, including the CRC of the Data.  
 
If the given Central Directory Record is marked as a test-only record that was created from an orphaned Local File Record, the XBZ_NO_CDREC Error Bit is set. If no corresponding Local File Record can be found, the XBZ_NO_LFDREC Error Bit is set. Otherwise, all Fields of the Local File Record are compared with the corresponding Fields of the given Central Directory Record. In addition, the actual CRC of the Data is compared to the saved CRC of the Local File Record. If any of the Fields or the CRC differs from the saved values, the corresponding Error Bit is set. The resulting Status/Error Code of the (File) Entry is used to update the (File) Entry's Status value, and the resulting value is then returned.  

Example

Open an existing Zip File named "MyArchive.zip" and test a File Entry named "File2Test.xxx" in it. Then show some of the possible test results and close the Zip File:  
 
LOCAL oZip := XbZLibZip():New('MyArchive.zip')  
LOCAL nStatus := oZip:TestEntry('File2Test.xxx')  
if nStatus == XBZ_ENTRY_OK  
   QOut('Entry "File2Test.xxx" is OK!')  
elseif nStatus[XBZ_CRC_WRONG]  
   QOut('Error: CRC of Entry "File2Test.xxx" is invalid!')  
else  
   QOut('Error: Entry "File2Test.xxx" might be corrupt!')  
endif  
oZip:Close()