ZipCentralDirectoryRecord
Previous  Top  Next

ZipCentralDirectoryRecord - The Central Directory Record of a Zip File Entry.

Description

For each Zip File Entry, there exists also a Central Directory Record at the end of the Zip File, which has a pointer to the beginning of the corresponding Local File Record. This Central Directory Record contains some additional information, like File Attributes and an optional File Comment besides all the information that is also available in the Local File Record. If the Central Directory Record is missing, the Local File Record and the corresponding Data cannot be found, and the Zip File is considered corrupted!  
 
The :Directory() method of the XbZLibZip object returns an Array of Central Directory Record objects, which can be used to retrieve information about each (File) Entry that is contained in a Zip File. It is strongly recommended to NEVER change any value of those Central Directory Records directly, as this could very easily lead to Zip File corruptions! Sometime it is necessary to create a new Central Directory Record to copy data from an existing Central Directory Record object to another. The easiest way to accomplish this is to use the Pseudo-Function "OClone()", which is defined in the header file "XbZLib.ch". Such a cloned copy of a Central Directory Record can be changed without any danger of messing up the Central Directory of an existing Zip File.  
 
This Central Directory Record is represented as a Structure in the XbZLib implementation. The following is the format of the Central Directory Record, as defined in the file "XbZLibSt.prg":  

STRUCTURE ZipCentralDirectoryRecord  
  CHAR  Signature       SIZE 4  // "PK" + chr(1) + chr(2)  
  UINT  VerMadeBy               // Set to 2.0 - DOS, Windows, OS/2 (FAT/VFAT/NTFS)  
  UINT  VerToExtract            // Set to 2.0 - DOS, Windows, OS/2 (FAT/VFAT/NTFS)  
  UINT  GPFlag                  // Set to "0" (Currently IGNORED)  
  UINT  CompMethod              // Only "0" (Stored) and "8" (Deflated) are supported  
  CHAR  FileTime        SIZE 4  
  CHAR  CRC             SIZE 4  
  ULONG CompSize  
  ULONG UnCompSize  
  UINT  FNameLen  
  UINT  ExtraFldLen             // Set to "0" (Currently IGNORED)  
  UINT  CommentLen  
  UINT  DiskNumStart            // Set to "0" (Currently IGNORED)  
  UINT  InternalFAttrib         // Set to "0" (Binary Data)  
  CHAR  ExternalFAttrib SIZE 4  // Only valid for DOS, Windows, OS/2 (FAT/VFAT/NTFS)  
  ULONG Offset  
  CHAR  FileName  
  CHAR  ExtraFld                // Set to "" (Currently IGNORED)  
  CHAR  Comment  
ENDSTRUCT  

The Version-To-Extract Flag is currently ignored when read and always set to 2.0 DOS/Windows when written, and the General Purpose Flag and the Extra Field are completely ignored, all of which could create compatibility problems with other Operating Systems and even other Windows/DOS Zip Programs and Zip Files created or updated by such programs. Additionally, the Spanning of Zip Files over multiple Disks/Files is not supported and the Disk Number Start field is always ignored and set to Zero "0"! A future version of XbZLib might be able to handle those Flags and multiple Disks/Files correctly, though.

Example

The following Example code creates an empty Central Directory Record object and sets some values:  

LOCAL oCDRec := ZipCentralDirectoryRecord():New()  
oCDRec:Signature := XBZ_CENTRAL_DIR_RECORD  
oCDRec:FileName  := "SomeFileName"  
oCDRec:FNameLen  := len(oCDRec:FileName)