AddEntry()
Previous  Top  Next

:AddEntry() - Add a single New (File) Entry to the Zip File.

Syntax

:AddEntry(<oZipCentralDirectoryRecord>,  
          <cData>]) --> nEntry  

Parameters

<oZipCentralDirectoryRecord>  
<oZipCentralDirectoryRecord> must be a valid Central Directory Record object that contains the updated information for the (File) Entry that should be added to the end of the Zip File.  

<cData>  
<cData> contains the Data of the (File) Entry that should be added to the end of the Zip File.  

Returns

This method returns the new number of (File) Entries in the Zip File, which is also the new (File) Entry's Index Number of the Central Directory Record that was added.  

Description

This method adds a new (File) Entry to the end of the Zip File, and also adds the corresponding new Central Directory Record object to the internal Central Directory Array and also adds a new entry to the internal Status Array.  
 
With this method it is possible to create multiple (File) Entries in the Zip File that have the (exact) same File Name, or that might contain characters that are not allowed in File Names (which is OS-dependent)! If this is done (inadvertently or on purpose), it could create problems with the automatic Extraction of Files in the :ExtractAll() and/or :Extract() methods, and could also interfere with the :Test() and :Fix() methods, as all of them rely on unique (and valid) File Names in the Zip File! Other programs (like PkZip, PkUnZip, PkZipFix, WinZip, PowerArchiver, etc.) that access such Zip Files might encounter the same type of problems!  

Example

Create and open a new Zip File named "NewArchive.zip" and open an existing Zip File named "OldArchive.zip" in Read-Only mode. Then manually copy the File Entry "File2Copy.xxx" from the "OldArchive.zip" to the "NewArchive.zip", save the changes, and close both Zip Files. The "OClone()" Pseudo-Function (from the "XbZLib.ch" header file) is needed to keep the original Central Directory Record object from oOldZip unchanged:  
 
oNewZip   := XbZLibZip():New('NewArchive.zip', XBZ_OPEN_CREATE)  
oOldZip   := XbZLibZip():New('OldArchive.zip', XBZ_OPEN_READ)  
oOldCDRec := oOldZip:FindEntry('File2Copy.xxx')  
oNewCDRec := OClone(oOldCDRec)  
oNewZip:AddEntry(oNewCDRec), oOldZip:GetData(oOldCDRec))  
oOldZip:Close()  
oNewZip:Close()