ReplaceEntry()
Previous  Top  Next

:ReplaceEntry() - Update/Replace a single (File) Entry in the Zip File.

Syntax

:ReplaceEntry(<cEntry> | <nEntry> | <oEntry>,  
              <cData>]) --> nEntry  

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 replaced/updated 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 replaced/updated in the Zip File.  
 
<oEntry>  
<oEntry> specifies the ZipCentralDirectoryRecord object of the (File) Entry that should be replaced/updated in the Zip File.  

<cData>  
<cData> contains the new Data of the (File) Entry that should replace the old Data of the existing (File) Entry in the Zip File.  

Returns

This method returns the (File) Entry's Index Number of the Central Directory Record that was replaced, or Zero (0), if the specified Entry could not be found.  

Description

This method replaces an existing (File) Entry in the Zip File, and also changes the corresponding Central Directory Record object and the internal Status Array entry. If the data has a different size than the existing data in the Zip File, all following (File) Entries will be adjusted accordingly, if it is not the last Entry in the Zip File.  
 
If a text string is specified as the Entry to be updated, it will be interpreted as the File Name of the Central Directory Entry that should be selected, and the appropriate Central Directory Record object will be located in the Central Directory Array. If no matching Central Directory Record could be found, nothing will be updated and the number 0 will be returned.  
 
If instead a number is specified as the Entry, it will be interpreted as the Index Number of the Central Directory Record Entry that should be updated. If that number does not correspond to a valid Central Directory Record Entry -- if it is 0 or its absolute value is greater than the number of Central Directory Record Entries -- nothing will be updated and the number 0 will be returned.  
 
If instead an object is specified as the Entry, it will be interpreted as the Central Directory Record object that should be updated. If that object is not a valid Central Directory Record Entry, nothing will be updated and the number 0 will be returned.  

Example

Open an existing Zip File named "MyArchive.zip". Then read the (contents of) a file named "File2Change.xxx" from disk and compress it. Then replace the existing data of "File2Change.xxx" in the "MyArchive.zip" file with the new data, but leave the File Name, Date/Time Stamp, and File Attributes unchanged. Then save and close the updated Zip File:  
 
LOCAL nError  := 0  
LOCAL oZip    := XbZLibZip():New('MyArchive.zip')  
LOCAL cBuffer := XbZ_FileRead('File2Change.xxx', @nError)  
LOCAL cData   := XbZ_Compress(@cBuffer, @nError)  
oZip:ReplaceEntry('File2Change.xxx', cData)  
oZip:Close()