Skip Navigation Links
Skip Navigation LinksHome > ZipArchive > How to Use > API Documentation

Represents a zip archive file. More...

#include <ZipArchive.h>

Public Types

enum  CloseAfterException { afNoException, afAfterException, afWriteDir }
 
enum  CommitMode { cmManual, cmOnChange }
 
enum  ConsistencyCheck {
  checkNone, checkCRC = 0x0001, checkLocalMethod = 0x0002, checkLocalSizes = 0x0004,
  checkLocalCRC = 0x0008, checkLocalFlag = 0x0010, checkLocalAll = checkLocalMethod | checkLocalSizes | checkLocalCRC | checkLocalFlag, checkDataDescriptor = 0x0100,
  checkVolumeEntries = 0x0200, checkDecryptionVerifier = 0x0400, checkTrimmedCentralDir = 0x0800, checkInvalidExtraData = 0x1000,
  checkAll = checkCRC | checkLocalAll | checkDataDescriptor | checkVolumeEntries | checkDecryptionVerifier | checkTrimmedCentralDir | checkInvalidExtraData, checkIgnoredByDefault = checkDataDescriptor | checkVolumeEntries
}
 
enum  FFCaseSens { ffDefault, ffCaseSens, ffNoCaseSens }
 
enum  OpenMode {
  zipOpen = 0x0001, zipOpenReadOnly = zipOpen | 0x0002, zipCreate = 0x0004, zipCreateAppend = zipCreate | 0x0008,
  zipModeSplit = 0x0100, zipModeBinSplit = 0x0200, zipModeSpan = 0x0400, zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan,
  zipCreateSplit = zipCreate | zipModeSplit, zipCreateBinSplit = zipCreate | zipModeBinSplit, zipCreateSpan = zipCreate | zipModeSpan, zipOpenSplit = zipOpenReadOnly | zipModeSplit,
  zipOpenBinSplit = zipOpenReadOnly | zipModeBinSplit
}
 
enum  Predict { prDir, prFile, prAuto }
 
enum  SegmCallbackType { scSpan = 0x01, scSplit = 0x02, scAll = scSpan | scSplit }
 
enum  Smartness {
  zipsmLazy = 0x0000, zipsmCPassDir = 0x0001, zipsmCPFile0 = 0x0002, zipsmNotCompSmall = 0x0004,
  zipsmCheckForEff = 0x0008, zipsmMemoryFlag = 0x0010, zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff, zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
  zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff, zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall, zipsmSmartest = zipsmSmartPass | zipsmSmartAdd, zipsmIgnoreDirectories = 0x0020,
  zipsmInternal01 = 0xf000
}
 
enum  SpecialFlags { sfNone, sfExhaustiveRead = 0x0001, sfLargeNotZip64 = 0x0002 }
 
enum  UnicodeMode {
  umNone = 0x00, umExtra = 0x01, umString = 0x02, umAll = umExtra | umString,
  umCustom = 0x04
}
 

Public Member Functions

bool AddNewFile (CZipAddNewFileInfo &info)
 
bool AddNewFile (LPCTSTR lpszFilePath, int iComprLevel=-1, bool bFullPath=true, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
 
bool AddNewFile (LPCTSTR lpszFilePath, LPCTSTR lpszFileNameInZip, int iComprLevel=-1, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
 
bool AddNewFile (CZipAbstractFile &af, LPCTSTR lpszFileNameInZip, int iComprLevel=-1, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
 
bool AddNewFiles (LPCTSTR lpszPath, ZipArchiveLib::CFileFilter &filter, bool bRecursive=true, int iComprLevel=-1, bool bSkipInitialPath=true, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
 
bool AddNewFiles (LPCTSTR lpszPath, LPCTSTR lpszFileMask=_T("*.*"), bool bRecursive=true, int iComprLevel=-1, bool bSkipInitialPath=true, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
 
bool AddNewFiles (CZipAddFilesEnumerator &addFilesEnumerator, ZipArchiveLib::CFileFilter &filter, bool bSkipInitialPath=true)
 
bool CanModify (bool bAllowNewSegmented=false, bool bNeedsClosed=true)
 
CZipString Close (int iAfterException=afNoException, bool bUpdateTimeStamp=false)
 
int CloseFile (LPCTSTR lpszFilePath=NULL, bool bAfterException=false)
 
int CloseFile (CZipFile &file)
 
bool CloseNewFile (bool bAfterException=false)
 
bool CommitChanges ()
 
void EnableFindFast (bool bEnable=true)
 
bool EncryptAllFiles ()
 
bool EncryptFile (ZIP_INDEX_TYPE uIndex)
 
bool EncryptFiles (CZipIndexesArray &aIndexes)
 
bool ExtractFile (ZIP_INDEX_TYPE uIndex, LPCTSTR lpszPath, bool bFullPath=true, LPCTSTR lpszNewName=NULL, ZipPlatform::FileOverwriteMode iOverwriteMode=ZipPlatform::fomRegular, CZipCompressor::COffsetsPair *pSeekPair=NULL, DWORD nBufSize=65536)
 
bool ExtractFile (ZIP_INDEX_TYPE uIndex, CZipAbstractFile &af, bool bRewind=true, CZipCompressor::COffsetsPair *pSeekPair=NULL, DWORD nBufSize=65536)
 
bool Finalize (bool bOnlyIfAuto=false)
 
ZIP_INDEX_TYPE FindFile (LPCTSTR lpszFileName, int iCaseSensitive=ffDefault, bool bFileNameOnly=false)
 
void FindMatches (LPCTSTR lpszPattern, CZipIndexesArray &ar, bool bFullPath=true)
 
void FlushBuffers ()
 
void GetAdvanced (int *piWriteBuffer=NULL, int *piGeneralBuffer=NULL, int *piSearchBuffer=NULL)
 
CZipString GetArchivePath () const
 
bool GetAutoFinalize () const
 
ZIP_SIZE_TYPE GetBytesBeforeZip () const
 
CZipActionCallbackGetCallback (CZipActionCallback::CallbackType iWhich)
 
bool GetCaseSensitivity () const
 
void GetCentralDirInfo (CZipCentralDir::CInfo &info) const
 
ZIP_SIZE_TYPE GetCentralDirSize (bool bWhole=true) const
 
int GetCommitMode () const
 
WORD GetCompressionMethod () const
 
ZIP_INDEX_TYPE GetCount (bool bOnlyFiles)
 
ZIP_INDEX_TYPE GetCount () const
 
const CZipCompressorGetCurrentCompressor () const
 
ZIP_VOLUME_TYPE GetCurrentVolume () const
 
int GetEncryptionMethod () const
 
bool GetFileInfo (CZipFileHeader &fhInfo, ZIP_INDEX_TYPE uIndex) const
 
CZipFileHeaderGetFileInfo (ZIP_INDEX_TYPE uIndex)
 
const CZipFileHeaderGetFileInfo (ZIP_INDEX_TYPE uIndex) const
 
ZIP_INDEX_TYPE GetFindFastIndex (ZIP_INDEX_TYPE iFindFastIndex) const
 
bool GetFromArchive (CZipArchive &zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName=NULL, ZIP_INDEX_TYPE uReplaceIndex=ZIP_FILE_INDEX_UNSPECIFIED, bool bKeepSystComp=false)
 
bool GetFromArchive (CZipArchive &zip, CZipIndexesArray &aIndexes, bool bKeepSystComp=false, bool bReplaceMode=false)
 
bool GetFromArchive (CZipArchive &zip, CZipStringArray &aNames, bool bKeepSystComp=false)
 
CZipString GetGlobalComment () const
 
int GetIgnoredConsistencyChecks () const
 
void GetIndexes (const CZipStringArray &aNames, CZipIndexesArray &aIndexes)
 
ZIP_INDEX_TYPE GetLastIndexAdded () const
 
ZIP_SIZE_TYPE GetOccupiedSpace () const
 
CZipString GetPassword () const
 
CZipString GetRootPath () const
 
int GetSpecialFlags () const
 
CZipStorageGetStorage ()
 
CZipStringStoreSettingsGetStringStoreSettings ()
 
int GetSystemCompatibility () const
 
CZipString GetTempPath () const
 
int GetUnicodeMode () const
 
bool IsClosed (bool bArchive=true) const
 
bool IsFullFileTimes () const
 
bool IsModified () const
 
bool IsPasswordSet () const
 
bool IsReadOnly ()
 
bool IsUseUtcFileTimes () const
 
bool Open (LPCTSTR szPathName, int iMode=zipOpen, ZIP_SIZE_TYPE uVolumeSize=0)
 
bool Open (CZipAbstractFile &af, int iMode=zipOpen, bool bAutoClose=false)
 
bool OpenFile (ZIP_INDEX_TYPE uIndex)
 
bool OpenFrom (CZipArchive &zip, CZipAbstractFile *pArchiveFile=NULL, bool bAllowNonReadOnly=false)
 
bool OpenNewFile (CZipFileHeader &header, int iLevel=CZipCompressor::levelDefault, LPCTSTR lpszFilePath=NULL)
 
CZipFileHeaderoperator[] (ZIP_INDEX_TYPE uIndex)
 
const CZipFileHeaderoperator[] (ZIP_INDEX_TYPE uIndex) const
 
bool OverwriteLocalHeader (ZIP_INDEX_TYPE uIndex)
 
CZipString PredictExtractedFileName (LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName=NULL) const
 
CZipString PredictFileNameInZip (LPCTSTR lpszFilePath, bool bFullPath, int iWhat=prAuto) const
 
ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive (CZipFileHeader &fh)
 
ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive (LPCTSTR lpszFilePath, bool bFullPath)
 
bool PrependData (LPCTSTR lpszFilePath, LPCTSTR lpszNewExt=)
 
bool PrependData (CZipAbstractFile &file, LPCTSTR lpszNewExt=NULL)
 
DWORD ReadFile (void *pBuf, DWORD uSize)
 
bool ReadLocalHeader (ZIP_INDEX_TYPE uIndex)
 
bool RemoveCentralDirectoryFromArchive ()
 
bool RemoveFile (ZIP_INDEX_TYPE uIndex, bool bRemoveData=true)
 
bool RemoveFiles (CZipIndexesArray &aIndexes)
 
bool RemoveFiles (const CZipStringArray &aNames)
 
bool ResetCurrentVolume ()
 
void ResetStringStoreSettings ()
 
bool SeekInFile (CZipCompressor::COffsetsPair *pPair)
 
void SetAdvanced (int iWriteBuffer=65536, int iGeneralBuffer=65536, int iSearchBuffer=32768)
 
bool SetAutoFinalize (bool bAutoFinalize=true)
 
const void SetBytesBeforeZip (ZIP_SIZE_TYPE uCount=0)
 
void SetCallback (CZipActionCallback *pCallback=NULL, int iWhich=CZipActionCallback::cbAll)
 
void SetCaseSensitivity (bool bCaseSensitive)
 
void SetCommitMode (int iCommitMode=cmOnChange)
 
bool SetCompressionMethod (WORD uCompressionMethod=CZipCompressor::methodDeflate)
 
void SetCompressionOptions (CZipCompressor::COptions *pOptions)
 
bool SetEncryptionMethod (int iEncryptionMethod=CZipCryptograph::encStandard)
 
void SetFullFileTimes (bool bFullFileTimes=true)
 
bool SetGlobalComment (LPCTSTR lpszComment, UINT codePage=ZIP_DEFAULT_CODE_PAGE)
 
void SetIgnoredConsistencyChecks (int iLevel=checkIgnoredByDefault)
 
bool SetPassword (LPCTSTR lpszPassword=NULL, UINT codePage=ZIP_DEFAULT_CODE_PAGE)
 
void SetRootPath (LPCTSTR szPath=NULL)
 
void SetSegmCallback (CZipSegmCallback *pCallback=NULL, int callbackType=scSpan)
 
void SetSpecialFlags (int iSpecialFlags)
 
bool SetSplitNamesHandler (CZipSplitNamesHandler &names)
 
bool SetSplitNamesHandler (CZipSplitNamesHandler *pNames, bool bAutoDelete=true)
 
void SetStringStoreSettings (const CZipStringStoreSettings &settings)
 
void SetStringStoreSettings (UINT uFileNameCodePage, bool bStoreNameInExtraData, UINT uCommentCodePage)
 
void SetStringStoreSettings (UINT uFileNameCodePage, bool bStoreNameInExtraData=false)
 
bool SetSystemCompatibility (int iSystemComp)
 
void SetTempPath (LPCTSTR lpszPath=NULL, bool bForce=true)
 
void SetUnicodeMode (int iMode)
 
void SetUseUtcFileTimes (bool bUseUtcFileTimes=true)
 
bool ShiftData (ZIP_SIZE_TYPE uOffset)
 
bool TestFile (ZIP_INDEX_TYPE uIndex, DWORD uBufSize=65536)
 
CZipString TrimRootPath (CZipPathComponent &zpc) const
 
ZIP_INDEX_TYPE WillBeDuplicated (LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly=false, int iWhat=prAuto)
 
bool WillEncryptNextFile () const
 
bool WriteNewFile (const void *pBuf, DWORD uSize)
 

Static Public Member Functions

static bool IsZipArchive (LPCTSTR lpszPathName)
 
static bool IsZipArchive (CZipAbstractFile &af, bool bAutoClose=false)
 
static bool RemovePathBeginning (LPCTSTR lpszBeginning, CZipString &szPath, ZIPSTRINGCOMPARE pCompareFunction)
 

Public Attributes

bool m_bSafePaths
 

Static Public Attributes

static const char m_gszCopyright []
 
static const char m_gszVersion []
 

Protected Types

enum  OpenFileType { extract = -1, nothing, compress }
 

Protected Member Functions

void ClearCompressor ()
 
void ClearCryptograph ()
 
virtual void CreateCompressor (WORD uMethod)
 
virtual void CreateCryptograph (int iEncryptionMethod)
 
CZipFileHeaderCurrentFile ()
 
bool EncryptFilesInternal (CZipIndexesArray *pIndexes)
 
void InitOnOpen (int iArchiveSystCompatib, CZipCentralDir *pSource=NULL)
 
void OpenInternal (int iMode)
 
bool OpenNewFile (CZipFileHeader &header, int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex)
 
void ReadLocalHeaderInternal (ZIP_INDEX_TYPE uIndex)
 
void WriteCentralDirectory (bool bFlush=true)
 

Protected Attributes

bool m_bAutoFinalize
 
bool m_bCaseSensitive
 
bool m_bStoreFullFileTimes
 
bool m_bUseUtcFileTimes
 
ZipArchiveLib::CZipCallbackProvider m_callbacks
 
CZipCentralDir m_centralDir
 
int m_iArchiveSystCompatib
 
DWORD m_iBufferSize
 
int m_iCommitMode
 
int m_iEncryptionMethod
 
int m_iFileOpened
 
CZipAutoBuffer m_pBuffer
 
CZipCompressorm_pCompressor
 
CZipCryptographm_pCryptograph
 
CZipAutoBuffer m_pszPassword
 
ZIPSTRINGCOMPARE m_pZipCompare
 
CZipStorage m_storage
 
CZipStringStoreSettings m_stringSettings
 
CZipString m_szRootPath
 
CZipString m_szTempPath
 
WORD m_uCompressionMethod
 

Detailed Description

Represents a zip archive file.

Member Enumeration Documentation

The values used in the CZipArchive::Close() method.

Enumerator:
afNoException 

Normal closing. Use it, when no exception was thrown while processing the archive.

afAfterException 

Use when an exception was thrown. The Close method doesn't write any data but performs necessary cleaning to reuse the CZipArchive object for another archive processing.

afWriteDir 

Use when an exception was thrown. The Close method writes the central directory structure to the archive, so that the archive should be usable.

The mode of committing changes.

See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
Enumerator:
cmManual 

Changes will be committed when the CommitChanges method is called or when closing the archive.

cmOnChange 

Changes will be committed immediately after they occur.

The values describing various archive consistency checks that the library performs. Instruct the library to skip selected checks using the SetIgnoredConsistencyChecks method.

Enumerator:
checkNone 

If used in the SetIgnoredConsistencyChecks method, examines all possible inconsistencies in an archive.

checkCRC 

Verifies CRC after decompression. Use it when working with Java TM Archives (jar). The CRC check is performed using CRC written in a central header when closing a file after extraction.

checkLocalMethod 

Verifies that the compression method written in a local header matches the compression method written in a central header.

checkLocalSizes 

Verifies that sizes of compressed and uncompressed data written in a local header match their counterparts in a central header. The compressed size in the local header is always ignored, if it is 0.

checkLocalCRC 

Verifies that the CRC written in a local header matches the CRC written in a central header.

checkLocalFlag 

Verifies that the general purpose flag value written in a local header matches its counterpart written in a central header.

checkLocalAll 

Examines all possible inconsistencies between central and local headers. These verifications are performed when opening a file for extraction.

checkDataDescriptor 

Verifies that values written in extra data descriptor match values written in central header. This verification is performed when closing a file after extraction, but only if a file has a data descriptor (see CZipFileHeader::IsDataDescriptor()). Ignored by default (it is consistent with behavior of popular archivers).

checkVolumeEntries 

Verifies that the number of volumes and entries are correctly reported.

checkDecryptionVerifier 

Verifies control bytes during CRC32 and AES decryption initialization.

checkTrimmedCentralDir 

Verifies that the central directory is written in its entirety.

checkInvalidExtraData 

Verifies that the extra data is valid.

checkAll 

Logical sum of all possible verifications.

checkIgnoredByDefault 

Checks that are ignored by default by the ZipArchive Library.

Case-sensitivity values used as the iCaseSensitive argument in the FindFile() method. The purpose of ffCaseSens and ffNoCaseSens is to temporarily change the default case-sensitivity for a single search. This is the reason, why these values cause the Find Fast array (which is a more permanent solution) to be built with the opposite meaning. In these cases the array is not rebuilt if it was built already.

Enumerator:
ffDefault 

Uses the default case-sensitivity as set with the SetCaseSensitivity method. If the Find Fast array was built before with a different case-sensitivity, it is rebuilt again, if it hasn't been built so far, it is built now with the default case-sensitivity.

ffCaseSens 

Performs a case-sensitive search. If the CZipArchive is non-case-sensitive, a less effective search is performed. It does not rebuild the Find Fast array, but if the array hasn't been built yet, it is built now as non-case-sensitive. You can use SetCaseSensitivity(true) and then ffDefault to build it as case-sensitive.

ffNoCaseSens 

Performs a non-case-sensitive search. If the CZipArchive is case-sensitive, a less effective search is performed. It does not rebuild the Find Fast array, but if the array hasn't been built yet, it is build now as case-sensitive. You can use SetCaseSensitivity(false) and then ffDefault to build it as non-case-sensitive.

enum CZipArchive::OpenFileType
protected

The open mode of the current file inside the archive.

Enumerator:
extract 

A file is opened for extraction.

nothing 

There is no file inside the archive opened.

compress 

A new file is opened for compression.

The archive open modes used in the CZipArchive::Open(LPCTSTR, int, ZIP_SIZE_TYPE) and CZipArchive::Open(CZipAbstractFile&, int, bool) methods.

Enumerator:
zipOpen 

Opens an existing archive.

zipOpenReadOnly 

Opens an existing archive as a read only file. This mode is intended to use in a self extract code, when opening an archive on a storage without the write access (e.g. CD-ROMS) or when sharing the central directory (see OpenFrom()). If you try to modify the archive in this mode, an exception will be thrown.

zipCreate 

Creates a new archive.

zipCreateAppend 

Creates a new archive, but allows appending the archive to an existing file (which can be for example a self-extracting stub).

zipCreateSplit 

Creates a split archive.

zipCreateBinSplit 

Creates a binary split archive.

zipCreateSpan 

Creates a span archive.

zipOpenSplit 

Opens an existing split archive. Use when opening split archives on removable devices or under Linux/OS X.

zipOpenBinSplit 

Opens an existing binary split archive.

The values used in the PredictFileNameInZip() method.

Enumerator:
prDir 

If lpszFilePath is a directory, appends a separator.

prFile 

Treats lpszFilePath as a common file.

prAuto 

Treats lpszFilePath as a directory only if it has a path separator appended.

The type of the callback object used during changing volumes in a segmented archive.

See Also
CZipArchive::SetSegmCallback
Enumerator:
scSpan 

The callback object will be set for operations on spanned archives only.

scSplit 

The callback object will be set for operations on split and binary split archives only.

scAll 

The callback object will be set for operations on spanned and split archives.

The levels of smartness of the ZipArchive Library while adding files with the CZipArchive::AddNewFile methods.

Note
If you use zipsmCheckForEff, you should use zipsmNotCompSmall as well, because the small file will be surely larger after compression, so that you can add it not compressed straight away. The compression level is always ignored for a directory and set to 0.
Enumerator:
zipsmLazy 

All the smartness options are turned off.

zipsmCPassDir 

Clears the password for directories.

zipsmCPFile0 

Clears the password for files of 0 size.

zipsmNotCompSmall 

Does not compress files smaller than 5 bytes - they are always stored larger than uncompressed.

zipsmCheckForEff 

If the compressed file is larger than uncompressed after compression, removes the file and stores it without the compression. In a segmented archive, a temporary file is used for that: if the file compression is efficient, the data is not compressed again, but moved from the temporary file to the archive. You can use the SetTempPath method to set the path where the file will be created or you can let the library figure it out (see SetTempPath). If the library could not find enough free space for the temporary file, the compression is performed the usual way.

zipsmMemoryFlag 

When combined with zipsmCheckForEff or zipsmCheckForEffInMem, it creates the temporary file in memory. This flag is effective also when replacing files (see the note at CZipAddNewFileInfo::m_uReplaceIndex).

zipsmCheckForEffInMem 

The same as zipsmCheckForEff, but the temporary file is created in memory instead. It has the meaning only in a segmented archive. Not segmented archives don't need a temporary file.

zipsmSmartPass 

The password policy (a combination of zipsmCPassDir and zipsmCPFile0).

zipsmSmartAdd 

Smart adding (a combination of zipsmNotCompSmall and zipsmCheckForEff).

zipsmSafeSmart 

Safe smart (all smartness levels but checking for the compression efficiency).

zipsmSmartest 

Smartness at its best.

zipsmIgnoreDirectories 

Ignores empty directories when using directory filter with the AddNewFiles method.

See Also
Compressing Data

Flags for workarounding various problems in archives.

See Also
SetSpecialFlags
Enumerator:
sfNone 

No special flags set.

sfExhaustiveRead 

Forces reading all headers from the central directory, even if the number of files reported by the archive is different. By default, the ZipArchive Library reads only the number of headers declared by the archive.

This method is useful when dealing with archives created with external software that puts more files inside an archive that it is permitted by the zip format. Such a situation can take place with archives created with e.g. BOMArchiveHelper (OS X utility), when the number of files exceeds 65,535.

sfLargeNotZip64 

Used to properly extract very large archives not conforming to Zip64 standard (encountered on OS X). This flag needs to be set manually, but is cleared automatically when the ZipArchive Library detects the current archive is a valid one.

The Unicode mode of the archive.

See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
Enumerator:
umNone 

No Unicode extensions are used.

umExtra 

Unicode support using extra fields.

umString 

Unicode support using UTF-8 strings.

umAll 

Unicode support using extra fields and UTF-8 strings.

umCustom 

The custom Unicode support.

Member Function Documentation

bool CZipArchive::AddNewFile ( CZipAddNewFileInfo info)

Adds a new file to the opened archive.

Parameters
infoSee CZipAddNewFileInfo for more information.
Returns
If false then the file was not added (in this case, you can still try to add other files); true otherwise.
Note
  • If you abort the operation from a callback object, while adding a file in a not segmented archive, the added data will be removed from the archive.
  • When an exception is thrown, you may need to call CloseNewFile with bAfterException set to true, to continue working with the archive.
See Also
Compressing Data
Progress Notifications: Using Callback Objects
In-Memory Archive Processing
AddNewFile(LPCTSTR, LPCTSTR, int, int, unsigned long)
AddNewFile(LPCTSTR, int, bool, int, unsigned long)
AddNewFile(CZipAbstractFile&, LPCTSTR, int, int, unsigned long)
AddNewFiles(LPCTSTR, ZipArchiveLib::CFileFilter&, bool, int, bool, int, unsigned long)
AddNewFiles(LPCTSTR, LPCTSTR, bool, int, bool, int, unsigned long)
AddNewFiles(CZipAddFilesEnumerator&, ZipArchiveLib::CFileFilter&, bool)
SetCallback
bool CZipArchive::AddNewFile ( LPCTSTR  lpszFilePath,
int  iComprLevel = -1,
bool  bFullPath = true,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536 
)

Adds a new file to the opened archive. See the AddNewFile(CZipAddNewFileInfo& ) method. The parameters are equivalent to CZipAddNewFileInfo member variables.

bool CZipArchive::AddNewFile ( LPCTSTR  lpszFilePath,
LPCTSTR  lpszFileNameInZip,
int  iComprLevel = -1,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536 
)

Adds a new file to the opened archive. See the AddNewFile(CZipAddNewFileInfo& ) method. The parameters are equivalent to CZipAddNewFileInfo member variables.

bool CZipArchive::AddNewFile ( CZipAbstractFile &  af,
LPCTSTR  lpszFileNameInZip,
int  iComprLevel = -1,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536 
)

Adds a new file to the opened archive. See the AddNewFile(CZipAddNewFileInfo& ) method. The parameters are equivalent to CZipAddNewFileInfo member variables.

bool CZipArchive::AddNewFiles ( LPCTSTR  lpszPath,
ZipArchiveLib::CFileFilter filter,
bool  bRecursive = true,
int  iComprLevel = -1,
bool  bSkipInitialPath = true,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536 
)

Adds new files to the opened archive from the specified directory using a filter.

Parameters
lpszPathThe root directory containing the files to add.
filterA filter that determines which files should be added.
bRecursivetrue, if the files from the subfolders of lpszPath should also be added; false otherwise.
iComprLevelThe level of compression. You can use values from 0 to 9 and -1 (meaning the default compression) or one of the CZipCompressor::CompressionLevel values.
bSkipInitialPathtrue, if the lpszPath directory should be removed from paths stored in the archive; false otherwise.
iSmartLevelThe smartness level of the file adding process. It can be one or more of the Smartness values.
nBufSizeThe size of the buffer used during file operations.
Returns
If false then some files were probably not added (in this case, you can still try to add other files); true otherwise.
See Also
Compressing Data
ZipArchiveLib::CFileFilter
ZipArchiveLib::CNameFileFilter
ZipArchiveLib::CGroupFileFilter
AddNewFiles(LPCTSTR, LPCTSTR, bool, int, bool, int, unsigned long)
AddNewFiles(CZipAddFilesEnumerator&, ZipArchiveLib::CFileFilter&, bool)
AddNewFile(CZipAddNewFileInfo&)
AddNewFile(LPCTSTR, LPCTSTR, int, int, unsigned long)
AddNewFile(LPCTSTR, int, bool, int, unsigned long)
AddNewFile(CZipAbstractFile&, LPCTSTR, int, int, unsigned long)
bool CZipArchive::AddNewFiles ( LPCTSTR  lpszPath,
LPCTSTR  lpszFileMask = _T("*.*"),
bool  bRecursive = true,
int  iComprLevel = -1,
bool  bSkipInitialPath = true,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536 
)
inline

Adds new files to the opened archive from the specified directory using a filename mask.

Parameters
lpszPathThe root directory containing the files to add.
lpszFileMaskThe filename mask to filter the files. Only files that has a filename matching this mask will be added to the archive. This method internally uses ZipArchiveLib::CNameFileFilter.
bRecursivetrue, if the files from the subfolders of lpszPath should also be added; false otherwise.
iComprLevelThe level of compression. You can use values from 0 to 9 and -1 (meaning the default compression) or one of the CZipCompressor::CompressionLevel values.
bSkipInitialPathtrue, if the lpszPath directory should be removed from paths stored in the archive; false otherwise.
iSmartLevelThe smartness level of the file adding process. It can be one or more of the Smartness values.
nBufSizeThe size of the buffer used during file operations.
Returns
If false then some files were probably not added (in this case, you can still try to add other files); true otherwise.
See Also
Searching in Archive
AddNewFiles(LPCTSTR, ZipArchiveLib::CFileFilter&, bool, int, bool, int, unsigned long)
AddNewFiles(CZipAddFilesEnumerator&, ZipArchiveLib::CFileFilter&, bool)
AddNewFile(CZipAddNewFileInfo&)
AddNewFile(LPCTSTR, LPCTSTR, int, int, unsigned long)
AddNewFile(LPCTSTR, int, bool, int, unsigned long)
AddNewFile(CZipAbstractFile&, LPCTSTR, int, int, unsigned long)
bool CZipArchive::AddNewFiles ( CZipAddFilesEnumerator addFilesEnumerator,
ZipArchiveLib::CFileFilter filter,
bool  bSkipInitialPath = true 
)

Adds new files to the opened archive using the given directory enumerator using a filter. To replace files in the archive while adding, use the CReplacingAddFilesEnumerator class.

Parameters
addFilesEnumeratorThe enumerator responsible for adding of files.
filterA filter that determines which files should be added.
bSkipInitialPathtrue, if the lpszPath directory should be removed from paths stored in the archive; false otherwise.
Returns
If false then some files were probably not added (in this case, you can still try to add other files); true otherwise.
See Also
Compressing Data
ZipArchiveLib::CFileFilter
ZipArchiveLib::CNameFileFilter
ZipArchiveLib::CGroupFileFilter
AddNewFiles(LPCTSTR, LPCTSTR, bool, int, bool, int, unsigned long)
AddNewFiles(LPCTSTR, ZipArchiveLib::CFileFilter&, bool, int, bool, int, unsigned long)
AddNewFile(CZipAddNewFileInfo&)
AddNewFile(LPCTSTR, LPCTSTR, int, int, unsigned long)
AddNewFile(LPCTSTR, int, bool, int, unsigned long)
AddNewFile(CZipAbstractFile&, LPCTSTR, int, int, unsigned long)
bool CZipArchive::CanModify ( bool  bAllowNewSegmented = false,
bool  bNeedsClosed = true 
)
inline

Returns the value indicating whether the archive can be modified.

Parameters
bAllowNewSegmentedIf true, new segmented archives can be modified; false otherwise.
bNeedsClosedIf true, the archive that has a file opened cannot be modified; false otherwise.
Returns
true, if the archive can be modified; false otherwise.
void CZipArchive::ClearCompressor ( )
inlineprotected

Releases the current compressor.

void CZipArchive::ClearCryptograph ( )
inlineprotected

Releases the current cryptograph.

CZipString CZipArchive::Close ( int  iAfterException = afNoException,
bool  bUpdateTimeStamp = false 
)

Closes the archive.

Parameters
iAfterExceptionOne of the CloseAfterException values.
bUpdateTimeStampIf true, the method sets the modification date of the zip file to the date of the newest file in the archive. In a segmented archive, only the last segment file will have the time stamp updated. You can use this option even without performing any additional processing on the archive, just open and close the archive.
Returns
The name of the last volume. It is useful when compressing split archives to know which file to use when opening the archive. The name is only returned when iAfterException is different from afAfterException.
Note
Does not throw any exceptions, if iAfterException is set to the afAfterException value.
See Also
Exceptions Handling
IsClosed
int CZipArchive::CloseFile ( LPCTSTR  lpszFilePath = NULL,
bool  bAfterException = false 
)

Closes the file opened for extraction in the archive and copy its date and attributes to the file pointed by lpszFilePath.

Parameters
lpszFilePathThe path of the file to have the date and attributes information updated. Make sure you have the read access to this file.
bAfterExceptionSet it to true, when you call this method after an exception was thrown, to allow further operations on the archive.
Returns
One of the following values:
  • 1 : The operation was successful.
  • 0 : There is no file opened.
  • -1 : Some bytes were left to uncompress - probably due to a bad password or a corrupted archive.
  • -2 : Setting extracted file date and attributes was not successful.
See Also
Extracting Data and Testing Archives
OpenFile
ReadFile
CloseFile(CZipFile&)
int CZipArchive::CloseFile ( CZipFile &  file)

Closes file and then calls the CloseFile(LPCTSTR, bool) method using the path of file as an argument. Don't call this method, if an exception was thrown before, call the CloseFile(LPCTSTR, bool) method instead.

Parameters
fileA CZipFile object of the extracted file. It must be opened.
Returns
The same values as the CloseFile(LPCTSTR, bool) method.
See Also
Extracting Data and Testing Archives
OpenFile
ReadFile
CloseFile(LPCTSTR, bool)
bool CZipArchive::CloseNewFile ( bool  bAfterException = false)

Closes the new file in the archive.

Returns
false, if there is no new file opened; true otherwise.
Parameters
bAfterExceptionIf true, the new file will be closed without writing anything. Set it to true after an exception was thrown. Use it also this way if an exception other than CZipException::abortedSafely was thrown from one of the AddNewFile methods.
See Also
Compressing Data
OpenNewFile
WriteNewFile
bool CZipArchive::CommitChanges ( )

Writes pending changes to the archive.

Returns
true, if changes were written successfully; false, if the current state of the archive is invalid for this method to be called.
Note
This method is also called when closing the archive regardless of the current commit mode.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data (Committing Modification Changes)
Modification of Archives: Replacing, Renaming, Deleting and Changing Data (Controlling Windows System File Cache)
SetCommitMode
GetCommitMode
IsModified
virtual void CZipArchive::CreateCompressor ( WORD  uMethod)
inlineprotectedvirtual

Creates a new compressor. You can override this method and implement your own compressor.

Parameters
uMethodThe requested data compression method.
See Also
CZipCompressor::CompressionMethod
virtual void CZipArchive::CreateCryptograph ( int  iEncryptionMethod)
inlineprotectedvirtual

Creates a new cryptograph. You can override this method and implement your own cryptograph.

Parameters
iEncryptionMethodThe requested encryption method.
See Also
CZipCryptograph::EncryptionMethod
CZipFileHeader* CZipArchive::CurrentFile ( )
protected

Returns the file currently opened for compression or decompression.

Returns
The currently opened file or NULL, if there is no file opened.
void CZipArchive::EnableFindFast ( bool  bEnable = true)

Enables or disables fast searching for files inside the archive using filenames.

See Also
Searching in Archive
FindFile
GetIndexes
GetFindFastIndex
bool CZipArchive::EncryptAllFiles ( )
inline

Encrypts all existing files in the archive using the current encryption method.

Returns
false, if the files could not be encrypted; true otherwise.
Note
See Also
Encryption Methods: How to Best Protect Your Data
SetEncryptionMethod
SetPassword
WillEncryptNextFile
EncryptFile
EncryptFiles
bool CZipArchive::EncryptFile ( ZIP_INDEX_TYPE  uIndex)
inline

Encrypts an existing file with a given index using the current encryption method.

Parameters
uIndexThe index of the file to encrypt.
Returns
false, if the file could not be encrypted; true otherwise.
Note
See Also
Encryption Methods: How to Best Protect Your Data
SetEncryptionMethod
SetPassword
WillEncryptNextFile
EncryptFiles
EncryptAllFiles
bool CZipArchive::EncryptFiles ( CZipIndexesArray &  aIndexes)
inline

Encrypts existing files with given indexes using the current encryption method.

Parameters
aIndexesThe indexes of files to encrypt.
Returns
false, if the files could not be encrypted; true otherwise.
Note
See Also
Encryption Methods: How to Best Protect Your Data
SetEncryptionMethod
SetPassword
WillEncryptNextFile
EncryptFile
EncryptAllFiles
bool CZipArchive::EncryptFilesInternal ( CZipIndexesArray *  pIndexes)
protected

See the description of EncryptFiles.

Parameters
pIndexes
Returns
false, if the files could not be encrypted; true otherwise.
See Also
EncryptFiles
bool CZipArchive::ExtractFile ( ZIP_INDEX_TYPE  uIndex,
LPCTSTR  lpszPath,
bool  bFullPath = true,
LPCTSTR  lpszNewName = NULL,
ZipPlatform::FileOverwriteMode  iOverwriteMode = ZipPlatform::fomRegular,
CZipCompressor::COffsetsPair pSeekPair = NULL,
DWORD  nBufSize = 65536 
)

Extracts a file from the archive. The argument lpszNewName may point to a full path and is influenced by bFullPath. If lpszNewName contains a drive specification then the drive part is removed unless m_bSafePaths is set to false.

Parameters
uIndexThe index of the file to extract.
lpszPathThe directory to extract the file to. May not be NULL.
bFullPathIn this paragraph the source path means:
  • The full filename stored in the archive, if lpszNewName is NULL
  • lpszNewName, if it is not NULL
The meaning of bFullPath is following:
  • If it is true, then the method extracts using the full source path, even if m_szRootPath is set. In this case the resulting file path is lpszPath plus the source path.
  • If it is false, then the destination file path is lpszPath plus the filename only extracted from the source path. In this case, if m_szRootPath is set (with SetRootPath), then before adding the source path to lpszPath, from the source path is removed the part that matches m_szRootPath (matching is performed starting from the beginning of both strings).
lpszNewNameThe new name of the file after extraction. If NULL, the original filename stored in the archive is used. May include a path information, but if bFullPath is false, only the filename is extracted from this value.
iOverwriteModeThe mode used when overwriting a file during extraction. Can be one or more of ZipPlatform::DeleteMode values.
pSeekPairIf not NULL, the file will be extracted starting from the seek position described by this value.
nBufSizeThe size of the buffer used while file operations.
Returns
true if successful; false otherwise.
Note
To extract files which filenames that match a specified pattern, use the FindMatches method.
See Also
Extracting Data and Testing Archives
Progress Notifications: Using Callback Objects
Creating Seekable Compressed Data
ExtractFile(ZIP_INDEX_TYPE, CZipAbstractFile&, bool, CZipCompressor::COffsetsPair*, DWORD)
FindMatches
SetCallback
bool CZipArchive::ExtractFile ( ZIP_INDEX_TYPE  uIndex,
CZipAbstractFile &  af,
bool  bRewind = true,
CZipCompressor::COffsetsPair pSeekPair = NULL,
DWORD  nBufSize = 65536 
)

The same as ExtractFile(ZIP_INDEX_TYPE, LPCTSTR, bool, LPCTSTR, ZipPlatform::FileOverwriteMode, CZipCompressor::COffsetsPair*, DWORD) but instead to a physical file, this method extracts data into a CZipAbstractFile object.

Parameters
uIndexThe index of the file to extract.
afAn abstract file to receive the decompressed data.
bRewindIf true, the memory file pointer is positioned at the beginning of the compressed data after compression. The rewind operation is performed even if extraction was aborted, but rewinding will not take place, if other exception than CZipException::abortedAction or CZipException::abortedSafely was thrown in the meantime.
pSeekPairIf not NULL, the file will be extracted starting from the seek position described by this value.
nBufSizeThe size of the buffer used while file operations.
Note
  • Writing of the decompressed data starts at the current position of the memory file. Keep this in mind, when you pass a CZipMemFile object that already contains data (or has a buffer attached) - its contents may be overwritten.
  • If you try to extract a directory, the method will return false.
See Also
In-Memory Archive Processing
Creating Seekable Compressed Data
ExtractFile(ZIP_INDEX_TYPE, LPCTSTR, bool, LPCTSTR, ZipPlatform::FileOverwriteMode, CZipCompressor::COffsetsPair*, DWORD)
bool CZipArchive::Finalize ( bool  bOnlyIfAuto = false)

Writes the central directory to the archive and flushes the internal buffers to the disk. After that the archive is finalized on the disk, but you can still modify it, if it is not a segmented archive.

Parameters
bOnlyIfAutoIf true, the archive will be finalized only when it is in the auto-finalize mode; false otherwise (default). This parameter is used mostly for internal purposes.
Returns
true, if the archive was finalized; false otherwise.
Note
  • This method cannot be used on existing segmented archives - they are not modifiable.
  • If you have an archive with a huge central directory, calling this function frequently will degrade the performance.
  • This method will not execute, if there are any pending modifications (see IsModified).
See Also
Compressing Data
FlushBuffers
SetAutoFinalize
GetAutoFinalize
ZIP_INDEX_TYPE CZipArchive::FindFile ( LPCTSTR  lpszFileName,
int  iCaseSensitive = ffDefault,
bool  bFileNameOnly = false 
)

Finds a file in the archive. This method enables the Find Fast feature, if it is not enabled already.

Parameters
lpszFileNameThe name of the file to be found in the archive. If the file in the archive is stored with the path information, you must specify it here or set bFileNameOnly to true. Use the same path separators as they are defined for your system as default ("\" for Windows and "/" for Linux and OS X).
iCaseSensitiveIt can be one of the FFCaseSens values.
bFileNameOnlyIf true, the method tries to find a filename without a path (a less effective search is performed). If you wish to find a directory name, do not end it with a path separator. The path separator is required, if you set bFileNameOnly to false.
Note
Use the SetCaseSensitivity method to set the global case-sensitivity.
Returns
The index of the file, if the file was found; ZIP_FILE_INDEX_NOT_FOUND if the file was not found.
See Also
Searching in Archive
EnableFindFast
void CZipArchive::FindMatches ( LPCTSTR  lpszPattern,
CZipIndexesArray &  ar,
bool  bFullPath = true 
)

Finds indexes of the files, which filenames match the specified pattern. The indexes are stored in the ar array. The indexes can be used then e.g. in deleting or extracting files.

Parameters
lpszPatternThe pattern to match. The case-sensitivity of the pattern is set to the global archive case-sensitivity (set with the SetCaseSensitivity method).
arThe array which will contain the resulting indexes. The contents of ar are not cleared, but the indexes are appended to it.
bFullPath
  • If true, the method matches the filename with path (if present) of the file. If the file is a directory, end it with a path separator or use a pattern that will recognize it.
  • If false, the method matches only the name of the file. If the file is a directory, do not end it with a path separator.
See Also
Searching in Archive
SetCaseSensitivity
ZipArchiveLib::CWildcard
void CZipArchive::FlushBuffers ( )
inline

Writes internal buffers to the storage file and flushes the file buffers to the disk.

See Also
Compressing Data
Finalize
void CZipArchive::GetAdvanced ( int *  piWriteBuffer = NULL,
int *  piGeneralBuffer = NULL,
int *  piSearchBuffer = NULL 
)
inline

Retrieves buffer sizes as set with the SetAdvanced() method.

Parameters
piWriteBuffer
piGeneralBuffer
piSearchBuffer
See Also
SetAdvanced
CZipString CZipArchive::GetArchivePath ( ) const

Returns the path of the currently opened archive segment.

Returns
The current volume's path or an empty string, if the archive is closed.
See Also
Segmented Archives: Splitting and Spanning
bool CZipArchive::GetAutoFinalize ( ) const
inline

Returns the current auto-finalize value.

Returns
The current auto-finalize value.
See Also
Compressing Data
SetAutoFinalize
Finalize
ZIP_SIZE_TYPE CZipArchive::GetBytesBeforeZip ( ) const
inline

Returns the number of extra bytes that are present before the actual archive in the archive file.

Returns
The number of bytes before the actual archive.
See Also
SetBytesBeforeZip
CZipActionCallback* CZipArchive::GetCallback ( CZipActionCallback::CallbackType  iWhich)
inline

Returns the callback object registered for the given notification.

Parameters
iWhichThe callback type. It can be one or more of the CZipActionCallback::CallbackType values.
Returns
The callback object set previously with SetCallback.
See Also
Progress Notifications: Using Callback Objects
SetCallback
CZipActionCallback
CZipActionCallback::CallbackType
bool CZipArchive::GetCaseSensitivity ( ) const
inline

Returns the current case sensitivity.

Returns
true, if the archive is case-sensitive; false otherwise.
See Also
SetCaseSensitivity
void CZipArchive::GetCentralDirInfo ( CZipCentralDir::CInfo info) const

Returns the central directory information.

Parameters
infoThe object to retrieve information data.
See Also
GetCentralDirSize
ZIP_SIZE_TYPE CZipArchive::GetCentralDirSize ( bool  bWhole = true) const
inline

Returns the central directory size.

Parameters
bWholeIf true, the return value includes the size of file headers.
Returns
The size of the central directory.
See Also
GetCentralDirInfo
int CZipArchive::GetCommitMode ( ) const
inline

Returns the current commit mode.

Returns
The current commit mode. It can be one of the CommitMode values.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
SetCommitMode
CommitChanges
WORD CZipArchive::GetCompressionMethod ( ) const
inline

Returns the current compression method used when adding files to the archive.

Returns
The current compression method. Is one of the CZipCompressor::CompressionMethod values.
See Also
SetCompressionMethod
ZIP_INDEX_TYPE CZipArchive::GetCount ( bool  bOnlyFiles)
inline

Returns the number of files in the archive.

Parameters
bOnlyFilesIf true, directories are not included in the total count; otherwise all entries are included.
Returns
The number of files in the archive.
See Also
Requesting Information, Predicting Names and Sizes
ZIP_INDEX_TYPE CZipArchive::GetCount ( ) const
inline

Returns the number of files in the archive.

Returns
The number of files in the archive. Note that depending on the ZipArchive compilation this may be an unsigned value or a signed value.
const CZipCompressor* CZipArchive::GetCurrentCompressor ( ) const
inline

Retrieves the current compressor. The type of the compressor depends on the compression method used for compressing or decompressing data.

See Also
SetCompressionMethod
ZIP_VOLUME_TYPE CZipArchive::GetCurrentVolume ( ) const

Returns the archive volume number currently being processed. The first volume has the number 1.

This method is useful while working with a segmented archive in creation to find out how many parts were already created. To find out how many parts are in an existing segmented archive, use the GetCentralDirInfo method.

Returns
A one-based number of the current volume or 0, if there is no current volume (the archive is closed).
See Also
Segmented Archives: Splitting and Spanning
int CZipArchive::GetEncryptionMethod ( ) const
inline

Returns the current encryption method.

Returns
One of CZipCryptograph::EncryptionMethod values.
See Also
SetEncryptionMethod
WillEncryptNextFile
bool CZipArchive::GetFileInfo ( CZipFileHeader fhInfo,
ZIP_INDEX_TYPE  uIndex 
) const

Returns the information about the file with the given index. The data is copied to fhInfo. This may not be optimal for querying large number of file. To avoid copying data, see the GetFileInfo(ZIP_INDEX_TYPE) method.

Parameters
fhInfoThe object to receive data.
uIndexA zero-based index of the file to get the information about.
Returns
true if successful; false otherwise.
See Also
Requesting Information, Predicting Names and Sizes
GetFileInfo(ZIP_INDEX_TYPE)
GetFileInfo(ZIP_INDEX_TYPE) const
operator[](ZIP_INDEX_TYPE)
operator[](ZIP_INDEX_TYPE) const
CZipFileHeader* CZipArchive::GetFileInfo ( ZIP_INDEX_TYPE  uIndex)

Returns the information about the file with the given index. This method provides a direct access to the file data. Apart from the situations described in Requesting Information, Predicting Names and Sizes, you should avoid modifications of the returned object.

Parameters
uIndexA zero-based index of the file to get the information about.
Returns
A CZipFileHeader object that directly points to a central directory entry in memory; NULL if the archive is closed or there is no such index in the archive.
See Also
Requesting Information, Predicting Names and Sizes
GetFileInfo(CZipFileHeader&, ZIP_INDEX_TYPE) const
GetFileInfo(ZIP_INDEX_TYPE) const
operator[](ZIP_INDEX_TYPE)
operator[](ZIP_INDEX_TYPE) const
const CZipFileHeader* CZipArchive::GetFileInfo ( ZIP_INDEX_TYPE  uIndex) const

Returns the information about the file with the given index. This method provides a direct access to the file data. This method does not allow modification of the returned object.

Parameters
uIndexA zero-based index of the file to get the information about.
Returns
A CZipFileHeader object that directly points to a central directory entry in memory; NULL if the archive is closed or there is no such index in the archive.
See Also
Requesting Information, Predicting Names and Sizes
GetFileInfo(CZipFileHeader&, ZIP_INDEX_TYPE) const
GetFileInfo(ZIP_INDEX_TYPE)
operator[](ZIP_INDEX_TYPE)
operator[](ZIP_INDEX_TYPE) const
ZIP_INDEX_TYPE CZipArchive::GetFindFastIndex ( ZIP_INDEX_TYPE  iFindFastIndex) const
inline

Allows to retrieve the order of sorted files after you enabled the Find Fast feature with the EnableFindFast() method.

Parameters
iFindFastIndexThe index of the file in the sorted array.
Returns
The index of the file in the central directory. You can use the return value in other methods that require the file index (such as GetFileInfo). This method returns -1, if you have not called EnableFindFast before or the archive is closed or the iFindFastIndex is out of range.
See Also
Searching in Archive
EnableFindFast
bool CZipArchive::GetFromArchive ( CZipArchive zip,
ZIP_INDEX_TYPE  uIndex,
LPCTSTR  lpszNewFileName = NULL,
ZIP_INDEX_TYPE  uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED,
bool  bKeepSystComp = false 
)
inline

Acquires a file with the given index from another archive. The compressed data of the file from another archive is copied to the current archive without decompression.

Parameters
zipThe opened archive to get the file from.
uIndexA zero-based index of the file to get from the zip archive.
lpszNewFileNameThe new filename to replace the old one from the zip archive. It can be NULL to leave the filename the same.
uReplaceIndexThe same as CZipAddNewFileInfo::m_uReplaceIndex. It can be ZIP_FILE_INDEX_UNSPECIFIED.
bKeepSystCompIf false, then the system compatibility of the file from the zip archive is converted to the current archive system compatibility, if they differ. Otherwise the source system compatibility is copied.
Returns
false, if the operation could not be performed (either of archives is closed, a file inside either of archives is opened, zip archive is segmented or the current archive is an existing segmented archive.
Note
  • This method will encrypt data, if an encryption method and a password are set and the file is not already encrypted.
  • When an exception is thrown, you may need to call CloseNewFile with bAfterException set to true, to continue working with the archive.
  • It is safe to abort the action (by returning false from the CZipActionCallback::Callback) in a not segmented archive and when no replacing is taking place. The file that is not entirely added is removed from the archive then.
See Also
Compressing Data
Progress Notifications: Using Callback Objects
GetFromArchive(CZipArchive&, CZipIndexesArray&, bool)
GetFromArchive(CZipArchive&, CZipStringArray&, bool)
SetCallback
SetAdvanced
SetEncryptionMethod
SetPassword
bool CZipArchive::GetFromArchive ( CZipArchive zip,
CZipIndexesArray &  aIndexes,
bool  bKeepSystComp = false,
bool  bReplaceMode = false 
)

Acquires files with the given indexes from another archive. The compressed data of the file from another archive is copied to the current archive without decompression.

Parameters
zipThe opened archive to get the file from.
aIndexesAn array of zero-based indexes of the files to acquire from the zip archive.
bKeepSystCompIf false, then the system compatibility of the file from the zip archive is converted to the current archive system compatibility, if they differ. Otherwise the source system compatibility is copied.
bReplaceModeIf true, then the files are checked for existence in the current archive by names. If a file with the same name exists, it is replaced, otherwise it is added.
Returns
false, if the operation could not be performed (either of archives is closed, a file inside either of archives is opened, zip archive is segmented or the current archive is an existing segmented archive.
Note
  • This method will encrypt data, if an encryption method and a password are set and the file is not already encrypted.
  • When an exception is thrown, you may need to call CloseNewFile with bAfterException set to true, to continue working with the archive.
  • It is safe to abort the action (by returning false from the CZipActionCallback::Callback) in a not segmented archive and when no replacing is taking place. The file that is not entirely added is removed from the archive then.
See Also
Compressing Data
Progress Notifications: Using Callback Objects
GetFromArchive(CZipArchive&, ZIP_INDEX_TYPE, LPCTSTR, ZIP_INDEX_TYPE, bool)
GetFromArchive(CZipArchive&, CZipStringArray&, bool)
SetCallback
SetAdvanced
SetEncryptionMethod
SetPassword
bool CZipArchive::GetFromArchive ( CZipArchive zip,
CZipStringArray &  aNames,
bool  bKeepSystComp = false 
)
inline

Acquires files with the given names from another archive. The compressed data of the file from another archive is copied to the current archive without decompression.

Parameters
zipThe opened archive to get the file from.
aNamesAn array of filenames to acquire from the zip archive.
bKeepSystCompIf false, then the system compatibility of the file from the zip archive is converted to the current archive system compatibility, if they differ. Otherwise the source system compatibility is copied.
Returns
false, if the operation could not be performed (either of archives is closed, a file inside either of archives is opened, zip archive is segmented or the current archive is an existing segmented archive.
Note
  • This method will encrypt data, if an encryption method and a password are set and the file is not already encrypted.
  • When an exception is thrown, you may need to call CloseNewFile with bAfterException set to true, to continue working with the archive.
  • It is safe to abort the action (by returning false from the CZipActionCallback::Callback) in a not segmented archive and when no replacing is taking place. The file that is not entirely added is removed from the archive then.
  • This method calls GetIndexes on the zip archive.
See Also
Compressing Data
Progress Notifications: Using Callback Objects
GetFromArchive(CZipArchive&, ZIP_INDEX_TYPE, LPCTSTR, ZIP_INDEX_TYPE, bool)
GetFromArchive(CZipArchive&, CZipIndexesArray&, bool)
SetCallback
SetAdvanced
SetEncryptionMethod
SetPassword
CZipString CZipArchive::GetGlobalComment ( ) const

Returns the global comment for the archive.

Returns
The global comment or an empty string if the archive is closed.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
SetGlobalComment
int CZipArchive::GetIgnoredConsistencyChecks ( ) const
inline

Returns the currently ignored consistency checks. It can be one or more of the ConsistencyCheck values.

See Also
SetIgnoredConsistencyChecks
void CZipArchive::GetIndexes ( const CZipStringArray &  aNames,
CZipIndexesArray &  aIndexes 
)

Returns indexes of the files with names stored in aNames and puts them into aIndexes. If a filename was not found, ZIP_FILE_INDEX_NOT_FOUND is inserted at the appropriate position in aIndexes.

Parameters
aNamesAn array of filenames inside the archive.
aIndexesAn array of indexes to be found.
Note
Use the SetCaseSensitivity method to set case-sensitivity.
See Also
Searching in Archive
EnableFindFast
ZIP_INDEX_TYPE CZipArchive::GetLastIndexAdded ( ) const
inline

Returns the index of the recently added file (if any).

Returns
The index of the recently added file or ZIP_FILE_INDEX_UNSPECIFIED if the index is unknown.
ZIP_SIZE_TYPE CZipArchive::GetOccupiedSpace ( ) const
inline

Calculates the actual size (in bytes) currently occupied by the archive.

Returns
The sum of the sizes: the number of bytes already written to the file, the number of bytes in the write buffer and the whole size of the central directory. If the archive or a volume is closed, the return value is 0.
See Also
Requesting Information, Predicting Names and Sizes
CZipString CZipArchive::GetPassword ( ) const

Returns the current archive password or an empty string if there is no password set.

Returns
The current password.
See Also
SetPassword
CZipString CZipArchive::GetRootPath ( ) const
inline

Returns the value set previously with the SetRootPath() method.

Returns
The current value of the m_szRootPath field.
See Also
SetRootPath
int CZipArchive::GetSpecialFlags ( ) const
inline

Returns the currently set special flags. It can be one or more of the SpecialFlags values.

See Also
SetSpecialFlags
CZipStorage* CZipArchive::GetStorage ( )
inline

Returns the underlying archive storage object.

Returns
The pointer to CZipStorage.
See Also
CZipStorage
CZipStringStoreSettings& CZipArchive::GetStringStoreSettings ( )
inline
int CZipArchive::GetSystemCompatibility ( ) const
inline
CZipString CZipArchive::GetTempPath ( ) const
inline

Returns the current temporary path used when compressing files.

Returns
The current temporary path.
See Also
SetTempPath
int CZipArchive::GetUnicodeMode ( ) const
inline

Returns the current Unicode mode.

Returns
The current Unicode mode. It can be one or more of the UnicodeMode values.
See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
void CZipArchive::InitOnOpen ( int  iArchiveSystCompatib,
CZipCentralDir pSource = NULL 
)
protected

Initializes the archive during opening.

Parameters
iArchiveSystCompatibThe system's compatibility of the archive.
pSourceIf not NULL, then it specifies the central directory for sharing.
bool CZipArchive::IsClosed ( bool  bArchive = true) const
inline

Tests if the whole archive or the current volume is closed.

Parameters
bArchive
If true, test for the whole archive. If false, test for the current volume only.
Returns
true if a file closed; false otherwise.
See Also
Close
bool CZipArchive::IsFullFileTimes ( ) const
inline

Returns the value indicating whether using of full file time resolution is set for the archive.

Returns
true, if full file times resolution is set for the archive; false otherwise.
See Also
SetFullFileTimes
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
bool CZipArchive::IsModified ( ) const
inline

Returns the value indicating whether there are any pending changes in the archive to be committed.

Returns
true, if there are changes left to be committed; false otherwise.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
CommitChanges
bool CZipArchive::IsPasswordSet ( ) const
inline

Returns the value indicating whether a password is set for the archive.

Returns
true, if a password is set for the archive; false otherwise.
bool CZipArchive::IsReadOnly ( )
inline

Returns the value indicating whether the archive can be modified. An archive is read-only when it is an existing segmented archive or it was opened with the zipOpenReadOnly flag.

Returns
true if the archive is read-only; false otherwise.
bool CZipArchive::IsUseUtcFileTimes ( ) const
inline

Returns the value indicating whether using of UTC file times is currently set for the archive.

Returns
true, if file times are stored in UTC in the archive; false otherwise.
See Also
SetUseUtcFileTimes
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
static bool CZipArchive::IsZipArchive ( LPCTSTR  lpszPathName)
static

Returns the value indicating whether the given file is a zip archive. To execute quickly, this method does not read a whole central directory, but also does not guarantee that the archive is not corrupted.

Parameters
lpszPathNameThe path of the file to examine.
Returns
true, if the archive is a zip archive; false otherwise.
static bool CZipArchive::IsZipArchive ( CZipAbstractFile &  af,
bool  bAutoClose = false 
)
static

Returns the value indicating whether the given file is a zip archive. To execute quickly, this method does not read a whole central directory, but also does not guarantee that the archive is not corrupted.

Parameters
afThe archive file to examine.
bAutoCloseIf true, the af file will be closed by this method; false otherwise.
Returns
true, if the archive is a zip archive; false otherwise.
bool CZipArchive::Open ( LPCTSTR  szPathName,
int  iMode = zipOpen,
ZIP_SIZE_TYPE  uVolumeSize = 0 
)

Opens or creates a zip archive.

Parameters
szPathNameThe path to the archive.
iModeIt can be one of the OpenMode values.
uVolumeSizeThe volume size in a split archive (relevant only for zipCreateSplit and zipCreateBinSplit modes). The size of the volume may be from 1 to 4,294,967,295. The bigger this value is - the faster is creation and extraction of segmented archives, because there are no volume changes.
Returns
true, if the archive was opened successfully; false, if the archive was already opened before.
Note
When opening a segmented archive, open the last volume.
See Also
Compressing Data
Extracting Data and Testing Archives
Segmented Archives: Splitting and Spanning
Open(CZipAbstractFile&, int, bool);
bool CZipArchive::Open ( CZipAbstractFile &  af,
int  iMode = zipOpen,
bool  bAutoClose = false 
)

Opens or creates an archive in memory. The CZipAbstractFile object is not closed after closing the archive, so that it is possible to work with it afterwards.

Parameters
afCZipAbstractFile object to store the archive data.
iModeThe open mode. The following values are valid: zipOpen, zipOpenReadOnly, zipCreate, zipCreateAppend. If you use zipCreate, the contents of the memory file are cleared. Use zipCreateAppend, if you want to append the archive at the end of the data contained in the memory file.
bAutoCloseIf true, the file will be closed when no longer used; false otherwise. Use false value (default) when operating on memory files.
Returns
true, if the archive was opened successfully; false, if the archive was already opened before or an invalid open mode was specified.
See Also
In-Memory Archive Processing
Open(LPCTSTR, int, ZIP_SIZE_TYPE);
bool CZipArchive::OpenFile ( ZIP_INDEX_TYPE  uIndex)

Opens the file with the given index in the archive for extracting. Not successful opening of the file doesn't lock the whole archive, so you can try to open another one (after catching an exception, if it was thrown)

Parameters
uIndexThe index of the file to open.
Returns
true, if successful; false otherwise. This method will also return false, if the compression method of the file is not supported by the ZipArchive Library.
Exceptions
CZipExceptionwith the CZipException::badPassword code, if the file is encrypted and the password was not set.
See Also
Extracting Data and Testing Archives
ReadFile
CloseFile
bool CZipArchive::OpenFrom ( CZipArchive zip,
CZipAbstractFile *  pArchiveFile = NULL,
bool  bAllowNonReadOnly = false 
)

Opens the archive from the already opened archive. Both archives will share the same central directory. The zip archive must be opened in read-only mode (unless allowNonReadOnly is set to true) and the newly opened archive will open as read-only as well.

Parameters
zipThe archive that provides the reference to the central directory. It must be a read-only archive. If the archive has no physical representation, the storage file of that archive has to return false from the CZipAbstractFile::HasFilePath() method. Alternatively, pArchiveFile can be used. When pArchiveFile is used, the zip archive cannot be segmented.
pArchiveFileWhen used, the current CZipArchive instance will use this file as the storage. This file must be opened in advance and the library will not attempt to close it at any time.
bAllowNonReadOnlyWhen set to true, the method will allow opening from a non-read only archive. However it is up to the user to ensure that the modifications to the zip archive won't corrupt the state of the CZipArchive object opened from it. Such a situation can happen when the zip archive is being modified and the current archive is reading at the same time.
Returns
true, if the new archive was successfully opened; false otherwise.
Note
If you use this method in a multithreaded environment, make sure that _ZIP_USE_LOCKING is defined in the _features.h file. Also make sure, that zip stays open until this method returns.
See Also
Extracting Data and Testing Archives
zipOpenReadOnly
void CZipArchive::OpenInternal ( int  iMode)
protected

Opens the archive in the given mode. Called by Open(LPCTSTR, int, ZIP_SIZE_TYPE) and Open(CZipAbstractFile&, int, bool).

Parameters
iModeThe mode.
bool CZipArchive::OpenNewFile ( CZipFileHeader header,
int  iLevel = CZipCompressor::levelDefault,
LPCTSTR  lpszFilePath = NULL 
)
inline

Adds a new file to the opened archive. The archive cannot be an existing (at the moment of opening the archive) segmented archive, because modifying such an archive is not possible with this version.

Parameters
headerThe structure that provides additional information about the added file and serves as a template for the properties of the new file. The following values can be set:
  • Use CZipFileHeader::SetFileName to set the filename (it may include a path). It will be stored inside the archive to represent this file.
  • Use CZipFileHeader::SetModificationTime to set the modification time. If lpszFilePath is not NULL it is overwritten and updated automatically.
  • Use CZipFileHeader::SetSystemAttr to set the attributes of the file. If lpszFilePath is not NULL this field is overwritten and updated automatically.
  • You can set CZipFileHeader::m_uLocalComprSize to the value of a predicted compressed size. Set it when using the Zip64 functionality and not using encryption or segmentation - you may set it to the size of the file that you want to compress. This is for prediction if the Zip64 extensions are needed, but you should not worry too much about setting this value, The ZipArchive Library will fix the headers if necessary - it just may save some processing.
  • Use CZipFileHeader::SetComment to set the file comment.
  • Modify CZipFileHeader::m_aLocalExtraData to include local extra fields.
  • Modify CZipFileHeader::m_aCentralExtraData to include central extra fields.
Other values are updated automatically. If the method returns true, system compatibility for this object is set to the correct value. Additionally if lpszFilePath was not NULL, the attributes and the time fields are filled with information retrieved from the file pointed by lpszFilePath.
iLevelThe level of compression. You can use values from 0 to 9 and -1 (meaning the default compression) or one of the CZipCompressor::CompressionLevel values. The level value has no effect, if the compression method set with the SetCompressionMethod is CZipCompressor::methodStore.
lpszFilePathThe path to the file to retrieve the date stamp and attributes from. These values are stored inside the archive.
Returns
false in the following cases:
  • The lpszFilePath is not NULL and the file attributes and data was not correctly retrieved.
  • A file is already opened for extraction or compression.
  • The archive is an existing segmented archive.
  • The maximum file count inside the archive has already been reached (65,535 for a standard archive and 0xFFFFFFFFFFFFFFFF for an archive in the Zip64 format).
true otherwise.
See Also
Compressing Data
Providing Custom Data: Extra Fields
WriteNewFile
CloseNewFile
bool CZipArchive::OpenNewFile ( CZipFileHeader header,
int  iLevel,
LPCTSTR  lpszFilePath,
ZIP_INDEX_TYPE  uReplaceIndex 
)
protected

See the description of OpenNewFile(CZipFileHeader&, int, LPCTSTR)

Parameters
header
iLevel
lpszFilePath
uReplaceIndexFor the internal use only.
See Also
OpenNewFile(CZipFileHeader&, int, LPCTSTR)
CZipFileHeader* CZipArchive::operator[] ( ZIP_INDEX_TYPE  uIndex)
inline

Returns the information about the file with the given index. This method provides a direct access to the file data. Apart from the situations described in Requesting Information, Predicting Names and Sizes, you should avoid modifications of the returned object.

Parameters
uIndexA zero-based index of the file to get the information about.
Returns
A CZipFileHeader object that directly points to a central directory entry in memory; NULL if the archive is closed or there is no such index in the archive.
See Also
Requesting Information, Predicting Names and Sizes
GetFileInfo(CZipFileHeader&, ZIP_INDEX_TYPE) const
GetFileInfo(ZIP_INDEX_TYPE)
GetFileInfo(ZIP_INDEX_TYPE) const
operator[](ZIP_INDEX_TYPE) const
const CZipFileHeader* CZipArchive::operator[] ( ZIP_INDEX_TYPE  uIndex) const
inline

Returns the information about the file with the given index. This method provides a direct access to the file data. This method does not allow modification of the returned object.

Parameters
uIndexA zero-based index of the file to get the information about.
Returns
A CZipFileHeader object that directly points to a central directory entry in memory; NULL if the archive is closed or there is no such index in the archive.
See Also
Requesting Information, Predicting Names and Sizes
GetFileInfo(CZipFileHeader&, ZIP_INDEX_TYPE) const
GetFileInfo(ZIP_INDEX_TYPE)
GetFileInfo(ZIP_INDEX_TYPE) const
operator[](ZIP_INDEX_TYPE)
bool CZipArchive::OverwriteLocalHeader ( ZIP_INDEX_TYPE  uIndex)

Writes the local header information of the file with the given index back to the archive.

Parameters
uIndexThe index of the file for which to write the local information.
Returns
true, if the information was successfully written; false otherwise.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
ReadLocalHeader
CZipString CZipArchive::PredictExtractedFileName ( LPCTSTR  lpszFileNameInZip,
LPCTSTR  lpszPath,
bool  bFullPath,
LPCTSTR  lpszNewName = NULL 
) const
 Predicts the full resulting filename with path after extraction. 

The parameters (except for the first) are in the form you would pass to the ExtractFile(ZIP_INDEX_TYPE, CZipAbstractFile&, bool, CZipCompressor::COffsetsPair*, DWORD) method. The method takes into account the root path set with the SetRootPath method.

Parameters
lpszFileNameInZipThe filename of the file inside the archive (may be NULL if lpszNewName is not NULL).
lpszPathThe same as in the ExtractFile method.
bFullPathThe same as in the ExtractFile method.
lpszNewNameThe same as in the ExtractFile method.
Returns
The predicted resulting file path.
CZipString CZipArchive::PredictFileNameInZip ( LPCTSTR  lpszFilePath,
bool  bFullPath,
int  iWhat = prAuto 
) const
Predicts the filename as it would be stored in the archive, when given parameters would be used with 

one of the AddNewFile() methods. The method takes into account the root path set with the SetRootPath method. You can use this method to eliminate duplicates before adding a list of files.

Parameters
lpszFilePathThe file path, the same as CZipAddNewFileInfo::m_szFilePath.
bFullPathThe same as CZipAddNewFileInfo::m_bFullPath.
iWhatOne of the Predict values to interpret lpszFilePath correctly.
Returns
The filename as it would be stored in the archive.
ZIP_SIZE_TYPE CZipArchive::PredictMaximumFileSizeInArchive ( CZipFileHeader fh)

Calculates the maximum number of bytes that the file represented by CZipFileHeader would occupy in the current archive.

You need to set the following members in the structure:

Additionally you may set:

Parameters
fhA template object pre-filled with data.
Returns
The maximum number of bytes the file would occupy in the archive.
Note
  • The method takes into account if the current archive is a segmented archive.
  • If the archive has a password set, the method assumes that the file would be stored encrypted in the archive (extra bytes may be added then depending on the encryption method).
  • This method calls CZipFileHeader::PrepareData
  • Zip64 only: The method takes into account the current file pointer position in the archive to determine the need for the Zip64 extensions and updates CZipFileHeader::m_uVolumeStart and CZipFileHeader::m_uOffset.
  • The method does not take into account a situation when a file would be compressed, but mostly stored blocks would be emitted by the Huffman compression engine. In this case extra 5 bytes are added per a single stored block. You should remove the file and store it instead when it happens (see zipsmCheckForEff).
See Also
PredictMaximumFileSizeInArchive(LPCTSTR, bool)
ZIP_SIZE_TYPE CZipArchive::PredictMaximumFileSizeInArchive ( LPCTSTR  lpszFilePath,
bool  bFullPath 
)

Calls the PredictMaximumFileSizeInArchive(CZipFileHeader&) method. Before calling, fills the CZipFileHeader structure with the filename as it would appear in the archive and sets the proper file size (unless lpszFilePath is a directory).

Parameters
lpszFilePathThe path to the file for which you want to predict the maximum size it would occupy.
bFullPathThe same as CZipAddNewFileInfo::m_bFullPath.
Returns
The maximum number of bytes the file would occupy in the archive.
See Also
PredictMaximumFileSizeInArchive(CZipFileHeader&)
bool CZipArchive::PrependData ( LPCTSTR  lpszFilePath,
LPCTSTR  lpszNewExt 
)

Inserts data contained in the file pointed by the lpszFilePath path before the archive data. You can use this method for example to convert the archive into a self-extracting archive (store a self-extracting stub inside lpszFilePath file). To perform prepending, the archive must be opened and no file must be opened for compression or extraction. This method will not work with segmented archives or archives, for which GetBytesBeforeZip method returns value different from 0.

Parameters
lpszFilePathThe path of the file to prepend to the archive.
lpszNewExtIf it is not NULL, then the extension of the archive is changed to this value after prepending data. Under Linux/Max OS X, this method sets executable permission for the owner after prepending. If renaming is performed, then the archive is closed before it. If this value is NULL, the no renaming is performed and the archive stays opened.
Returns
true, if data from lpszFilePath file was prepended (and optionally renamed) successfully; false otherwise.
Note
Calls the CZipActionCallback::cbMoveData callback.
See Also
Self-Extracting Archives
ShiftData
PrependData(CZipAbstractFile&, LPCTSTR)
bool CZipArchive::PrependData ( CZipAbstractFile &  file,
LPCTSTR  lpszNewExt = NULL 
)

Inserts data contained in the file before the archive data. You can use this method for example to convert the archive into a self-extracting archive (store a self-extracting stub inside file). To perform prepending, the archive must be opened and no file must be opened for compression or extraction. This method will not work with segmented archives or archives, for which GetBytesBeforeZip method returns value different from 0.

Parameters
fileThe file containing data to insert before the archive data. The file should be opened.
lpszNewExtIf it is not NULL, then the extension of the archive is changed to this value after prepending data. Under Linux/Max OS X, this method sets executable permission for the owner after prepending. If renaming is performed, then the archive is closed before it. If this value is NULL, the no renaming is performed and the archive stays opened
Returns
true, if data from file was prepended successfully; false otherwise.
Note
Calls the CZipActionCallback::cbMoveData callback.
See Also
Self-Extracting Archives
ShiftData
PrependData(LPCTSTR, LPCTSTR)
DWORD CZipArchive::ReadFile ( void *  pBuf,
DWORD  uSize 
)

Reads data from the currently opened file and decompresses it to pBuf.

Parameters
pBufThe buffer to receive the decompressed data.
uSizeThe size of pBuf.
Returns
The number of bytes read.
See Also
Extracting Data and Testing Archives
OpenFile
CloseFile
bool CZipArchive::ReadLocalHeader ( ZIP_INDEX_TYPE  uIndex)

Reads the local header information of the file with the given index.

Parameters
uIndexThe index of the file for which to update the local information.
Returns
true, if the information was successfully updated; false otherwise.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
OverwriteLocalHeader
void CZipArchive::ReadLocalHeaderInternal ( ZIP_INDEX_TYPE  uIndex)
inlineprotected

Reads the local header information of the file with the given index.

Parameters
uIndexThe index of the file for which to update the local information.
bool CZipArchive::RemoveCentralDirectoryFromArchive ( )

Removes the central directory from the archive. You may then modify central extra fields and write the central directory back to the archive afterwards (use the Close method).

Returns
true, if the central directory was successfully removed; false otherwise.
See Also
Providing Custom Data: Extra Fields
bool CZipArchive::RemoveFile ( ZIP_INDEX_TYPE  uIndex,
bool  bRemoveData = true 
)

Deletes the file with the given index from the archive. If you plan to delete more than one file, use the RemoveFiles(CZipIndexesArray&) or RemoveFiles(const CZipStringArray&) method. These methods are optimized for deleting multiple files.

Parameters
uIndexA zero-based index of the file to delete.
bRemoveDataIf true (default), removes the file data from the archive. If false, removes the file only from the central directory.
Returns
false, if the file could not be removed; true otherwise.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
RemoveFiles(CZipIndexesArray&)
RemoveFiles(const CZipStringArray&)
SetCallback
FindMatches
bool CZipArchive::RemoveFiles ( CZipIndexesArray &  aIndexes)

Deletes files from the archive. Sorts aIndexes in the ascending order.

Parameters
aIndexesAn array of zero-based indexes of the files to delete.
Returns
false, if files could not be removed; true otherwise.
Note
To remove files which filenames match a specified pattern, use the FindMatches method before to find the indexes.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
RemoveFile
RemoveFiles(const CZipStringArray& )
SetCallback
FindMatches
bool CZipArchive::RemoveFiles ( const CZipStringArray &  aNames)

Delete files from the archive.

Parameters
aNamesAn array of filenames to delete;
Returns
false, if files could not be removed; true otherwise.
Note
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
RemoveFile
RemoveFiles(CZipIndexesArray&)
SetCallback
EnableFindFast
static bool CZipArchive::RemovePathBeginning ( LPCTSTR  lpszBeginning,
CZipString &  szPath,
ZIPSTRINGCOMPARE  pCompareFunction 
)
static

Removes lpszBeginning from the beginning of szPath. Both argument are considered to be paths - they must match up to the path separator.

Parameters
lpszBeginningThe beginning to remove.
szPathThe path to have the beginning removed.
pCompareFunctionThe compare function used (see m_pZipCompare).
Returns
true, if the path beginning was removed; false otherwise.
bool CZipArchive::ResetCurrentVolume ( )

Resets the current volume while extracting a span archive when an invalid disk was inserted.

Returns
true, if the method succeeded; false, if the current state of the archive is invalid for this method to be called.
See Also
Segmented Archives: Splitting and Spanning
void CZipArchive::ResetStringStoreSettings ( )
inline

Sets the current settings that control storing of filenames and comments in the archive to their default values considering the current system compatibility of the archive (see GetSystemCompatibility()).

See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
SetStringStoreSettings(const CZipStringStoreSettings&)
SetStringStoreSettings(UINT, bool, UINT)
SetStringStoreSettings(UINT, bool)
GetStringStoreSettings
bool CZipArchive::SeekInFile ( CZipCompressor::COffsetsPair pPair)

Performs a seeking in compressed data. A file must be opened for extraction.

Parameters
pPairThe offsets pair that described the location of a synchronization block.
See Also
Creating Seekable Compressed Data
OpenFile
CloseFile
void CZipArchive::SetAdvanced ( int  iWriteBuffer = 65536,
int  iGeneralBuffer = 65536,
int  iSearchBuffer = 32768 
)

Sets the internal buffer sizes. No buffer size can be set smaller than 1024. Use this method before opening the archive. The optimal size for the write buffer for a segmented archive is the size of the volume.

Parameters
iWriteBufferThe write buffer size. See also CZipStorage::m_iWriteBufferSize.
iGeneralBufferA helper buffer used in moving data, deleting, getting (GetFromArchive) files, renaming and replacing. This buffer is not used for compression and decompression. For these purposes, use the CZipCompressor::COptions::m_iBufferSize option.
iSearchBufferA buffer used in searching for the central directory. See also CZipStorage::m_iLocateBufferSize.
See Also
GetAdvanced
SetCompressionOptions
bool CZipArchive::SetAutoFinalize ( bool  bAutoFinalize = true)

Sets the CZipArchive object to call the Finalize() method after each operation that modifies the archive (apart from changing central extra fields). It is useful when you want to prevent the loss of data in case of the program crash - the zip file will then be finalized on the disk. Use it after opening the archive.

Note
  • You can set auto-finalize only for non-segmented archives.
  • If you have an archive with a huge central directory, enabling auto-finalize will degrade the performance.
  • This method will have no effect, when there are any pending modifications (see IsModified).
See Also
Compressing Data
Finalize
GetAutoFinalize
const void CZipArchive::SetBytesBeforeZip ( ZIP_SIZE_TYPE  uCount = 0)
inline

Sets the number of extra bytes that are present before the actual archive in the archive file. The library usually tries to automatically calculate this value, but this may not be possible under some conditions.

Parameters
uCountThe number of bytes before the actual archive.
See Also
GetBytesBeforeZip
void CZipArchive::SetCallback ( CZipActionCallback pCallback = NULL,
int  iWhich = CZipActionCallback::cbAll 
)
inline

Registers the callback object to receive specified notifications.

Parameters
pCallbackThe callback object to receive notifications. Set it to NULL to stop receiving the selected notifications.
iWhichThe callback type to register for (or unregister from). It can be one or more of the CZipActionCallback::CallbackType values.
See Also
Progress Notifications: Using Callback Objects
CZipActionCallback
CZipActionCallback::CallbackType
GetCallback
void CZipArchive::SetCaseSensitivity ( bool  bCaseSensitive)
inline

Sets the default archive case-sensitivity. The default CZipArchive case-sensitivity depends on the system and is set as follows:

  • on Windows: false
  • on other platforms: true

Calling this method affects the following methods:

Parameters
bCaseSensitiveThe case-sensitivity to be used.
Note
Set it before using one of the mentioned methods or leave it as it was set by default.
void CZipArchive::SetCommitMode ( int  iCommitMode = cmOnChange)
inline

Sets the commit mode.

Parameters
iCommitModeThe mode to set. It can be one of the CommitMode values.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
GetCommitMode
CommitChanges
bool CZipArchive::SetCompressionMethod ( WORD  uCompressionMethod = CZipCompressor::methodDeflate)

Sets the compression method used when compressing file. If affects the files that are added to the archive after calling this method.

Parameters
uCompressionMethodThe compression method to use. Valid values are CZipCompressor::methodStore, CZipCompressor::methodDeflate and CZipCompressor::methodBzip2.
Returns
true, if the compression method is supported by the ZipArchive Library and was successfully set; false otherwise.
Note
The compression method used for extraction is automatically determined from the information written in the archive.
See Also
Compressing Data
CZipCompressor::IsCompressionSupported
GetCompressionMethod
GetCurrentCompressor
void CZipArchive::SetCompressionOptions ( CZipCompressor::COptions pOptions)
inline

Sets the compression options for an appropriate compressor. The library automatically detects to which compressor the options apply by examining the return value from the CZipCompressor::COptions::GetType() method. If a file is currently opened for compression or decompression, the options will have no effect on the current file processing. A sample that illustrates setting options can be found at Compressing Data.

Parameters
pOptionsThe options to set. The NULL value has no effect. The object is no longer needed and can be safely released after this method returns.
See Also
Compressing Data
GetCurrentCompressor
CZipCompressor::GetOptions
SetAdvanced
bool CZipArchive::SetEncryptionMethod ( int  iEncryptionMethod = CZipCryptograph::encStandard)

Sets the encryption method when encrypting files. You can encrypt different files using different methods. You need to set the password with the SetPassword method for the encryption to work. It is necessary to set the encryption method only when compressing. When decompressing, the encryption method will be detected automatically.

Parameters
iEncryptionMethodOne of the CZipCryptograph::EncryptionMethod values.
Returns
false if selected encryption method is not supported or a file is opened for compression; true otherwise.
See Also
Encryption Methods: How to Best Protect Your Data
SetPassword
CZipCryptograph::EncryptionMethod
GetEncryptionMethod
WillEncryptNextFile
void CZipArchive::SetFullFileTimes ( bool  bFullFileTimes = true)
inline

Enables using of full times resolution when creating files in the archive. Note, the information whether the times are stored in UTC or local times is not stored in the archive.

See Also
IsFullFileTimes
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
bool CZipArchive::SetGlobalComment ( LPCTSTR  lpszComment,
UINT  codePage = ZIP_DEFAULT_CODE_PAGE 
)

Sets the global comment in the archive.

Parameters
lpszCommentThe comment to set.
codePageThe code page to use.
Returns
false, if the archive is closed or it is an existing segmented archive or any file is opened in the archive for extraction or compression; true otherwise.
See Also
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
GetGlobalComment
void CZipArchive::SetIgnoredConsistencyChecks ( int  iLevel = checkIgnoredByDefault)
inline

Sets the consistency checks to ignore while processing the archive. Allows opening archives which are not entirely consistent, but nevertheless the compressed data is correct. Set it before or after opening an archive.

Parameters
iLevelThe consistency check. It can be one or more of the ConsistencyCheck values.
See Also
ConsistencyCheck
GetIgnoredConsistencyChecks
bool CZipArchive::SetPassword ( LPCTSTR  lpszPassword = NULL,
UINT  codePage = ZIP_DEFAULT_CODE_PAGE 
)

Sets a password for the file to be opened or created. Use this method before opening or adding a file, but after opening the archive. For security reasons, the password is cleared during opening and closing of the archive. For the encryption to work, encryption method must be set to other value than CZipCryptograph::encNone.

Parameters
lpszPasswordThe password. Set it to NULL or an empty string to clear the password.
codePageThe code page to use.
Returns
false if the password cannot be changed at this time; true otherwise.
See Also
Encryption Methods: How to Best Protect Your Data
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
GetPassword
SetEncryptionMethod
WillEncryptNextFile
void CZipArchive::SetRootPath ( LPCTSTR  szPath = NULL)

Sets the path fragment to be removed from the beginning of the full path when adding or extracting a file.

Use it, if you don't want to use the full path (by setting the bFullPath parameter in AddNewFile or ExtractFile to true) and you don't want to remove the whole path either (be setting the same parameter to false), but you want to remove only a specific beginning. Use it after opening the archive and before calling the AddNewFile or ExtractFile methods.

Parameters
szPathThe string that you want to be removed from the beginning of the path of the file in the archive. Set it to NULL to stop removing the path beginning.
Note
Set the case-sensitivity with the SetCaseSensitivity method.
See Also
AddNewFile
ExtractFile
GetRootPath
void CZipArchive::SetSegmCallback ( CZipSegmCallback pCallback = NULL,
int  callbackType = scSpan 
)

Sets the callback object used during operations on a segmented archive to change volumes in spanned and split archives. Set it before opening the archive. If you open a spanned archive and don't set the callback object, the exception CZipException::noCallback will be thrown. Setting the callback object is not required for a split archive.

Callback object's method CZipSegmCallback::Callback is called when the next volume is processed in a segmented archive. Calling CZipArchive methods from inside this method may result in an unexpected behavior.

Parameters
pCallbackThe address of the callback object. Set it to NULL to clear the callback.
callbackTypeThe type of the callback to set. It can be one of the SegmCallbackType values.
See Also
Segmented Archives: Splitting and Spanning
CZipSegmCallback
void CZipArchive::SetSpecialFlags ( int  iSpecialFlags)
inline

Sets special flags. It can be one or more of the SpecialFlags values. Call this method before opening an archive.

See Also
GetSpecialFlags
bool CZipArchive::SetSplitNamesHandler ( CZipSplitNamesHandler names)
inline

Sets the current split names handler.

Parameters
namesThe handler to set.
Note
Set it each time before an archive is opened.
See Also
Segmented Archives: Splitting and Spanning
SetSplitNamesHandler(CZipSplitNamesHandler*, bool)
CZipSplitNamesHandler
bool CZipArchive::SetSplitNamesHandler ( CZipSplitNamesHandler pNames,
bool  bAutoDelete = true 
)
inline

Sets the current split names handler.

Parameters
pNamesThe names to set.
bAutoDeleteIf true, the handler will be automatically deleted when it is no longer needed; false otherwise.
Note
Set it each time before an archive is opened.
See Also
Segmented Archives: Splitting and Spanning
SetSplitNamesHandler(CZipSplitNamesHandler&)
CZipSplitNamesHandler
void CZipArchive::SetStringStoreSettings ( const CZipStringStoreSettings settings)
inline

Sets the current settings that control storing of filenames and comments in the archive.

Parameters
settingsThe settings to set.
See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
SetStringStoreSettings(UINT, bool, UINT)
SetStringStoreSettings(UINT, bool)
ResetStringStoreSettings
GetStringStoreSettings
void CZipArchive::SetStringStoreSettings ( UINT  uFileNameCodePage,
bool  bStoreNameInExtraData,
UINT  uCommentCodePage 
)
inline

Sets the current settings that control storing of filenames and comments in the archive.

Parameters
uFileNameCodePageThe code page for filenames.
bStoreNameInExtraDataIf true, the encoded filenames are stored in central extra fields.
uCommentCodePageThe code page for comments.
See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
SetStringStoreSettings(const CZipStringStoreSettings&)
SetStringStoreSettings(UINT, bool)
ResetStringStoreSettings
GetStringStoreSettings
void CZipArchive::SetStringStoreSettings ( UINT  uFileNameCodePage,
bool  bStoreNameInExtraData = false 
)
inline

Sets the current settings that control storing of filenames and comments in the archive. The code page for comments stays the same when calling this method.

Parameters
uFileNameCodePageThe code page for filenames.
bStoreNameInExtraDataIf true, the encoded filenames are stored in central extra fields.
See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
SetStringStoreSettings(const CZipStringStoreSettings&)
SetStringStoreSettings(UINT, bool, UINT)
ResetStringStoreSettings
GetStringStoreSettings
bool CZipArchive::SetSystemCompatibility ( int  iSystemComp)

Sets the system compatibility of the archive. Use it after opening the archive, but before adding a new file.

Parameters
iSystemCompThe new system compatibility to use. It can be one of the ZipCompatibility::ZipPlatforms values.
Returns
false, if the value iSystemComp is not supported or it is not possible to set the value at this moment; true otherwise.
Note
If using the custom Unicode mode (see Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords) and the filename code page is standard for the current system compatibility, the ZipArchive Library will change the filename code page to be default for the new system compatibility.
See Also
Compressing Data
GetSystemCompatibility
CZipFileHeader::GetSystemCompatibility
ZipCompatibility::ZipPlatforms
ZipPlatform::GetSystemID
void CZipArchive::SetTempPath ( LPCTSTR  lpszPath = NULL,
bool  bForce = true 
)

Sets the temporary path used when compressing files and there is a need for a temporary archive. Temporary files are used when replacing or when compressing a segmented archive with the zipsmCheckForEff flag. If the path is not set or it does not exists or there is not enough free space in it, then the ZipArchive Library first tries the following folders in the given order for sufficient free space:

  • system default temporary directory,
  • the current directory.

If all above fails, no temporary file is created and the compression is performed the usual way.

Parameters
lpszPathThe path used for storing temporary files. Set it to NULL, to clear the temporary path and let the ZipArchive Library figure it out (see above).
bForceIf lpszPath is not NULL and this parameter set to true the directory is created, if it doesn't exist. Otherwise the ZipArchive Library tries to figure out the location for temporary files by itself (see above).
See Also
GetTempPath
AddNewFile
Smartness
void CZipArchive::SetUnicodeMode ( int  iMode)
inline

Sets the current Unicode mode.

Parameters
iModeThe Unicode mode to set. It can be one or more of the UnicodeMode values.
See Also
Unicode Support: Using Non-English Characters in Filenames, Comments and Passwords
void CZipArchive::SetUseUtcFileTimes ( bool  bUseUtcFileTimes = true)
inline

Enables using of UTC file times when creating files in the archive.

See Also
IsUseUtcFileTimes
Modification of Archives: Replacing, Renaming, Deleting and Changing Data
bool CZipArchive::ShiftData ( ZIP_SIZE_TYPE  uOffset)

Shifts data inside the archive to make an empty space at the beginning of the archive. Into this empty space, you can copy for example a self-extracting stub. To perform shifting, the archive must be opened and no file must be opened for compression or extraction. This method will not work with segmented archives or archives, for which GetBytesBeforeZip method returns value different from 0.

Parameters
uOffsetThe number of bytes to shift the archive data by.
Returns
true, if data was shifted successfully; false otherwise.
Note
Calls the CZipActionCallback::cbMoveData callback.
See Also
Self-Extracting Archives
PrependData(CZipAbstractFile&, LPCTSTR)
PrependData(LPCTSTR, LPCTSTR)
bool CZipArchive::TestFile ( ZIP_INDEX_TYPE  uIndex,
DWORD  uBufSize = 65536 
)

Tests the file with the given index for the integrity. The method throws exceptions but performs all the necessary cleanup before, so that the next file can be tested after catching the exception.

Parameters
uIndexThe index of the file to test.
uBufSizeThe size of the buffer used during extraction.
Returns
false, if the incorrect action has been taken (when OpenFile or GetFileInfo returned false or uBufSize is 0); true otherwise. If the file didn't passed the test or there was a disk I/O error or the supplied password was incorrect, an exception is thrown.
See Also
Extracting Data and Testing Archives
SetCallback
CZipString CZipArchive::TrimRootPath ( CZipPathComponent zpc) const

Removes the root path from zpc.

Parameters
zpcThe path to have the common beginning removed from.
See Also
SetRootPath
ZIP_INDEX_TYPE CZipArchive::WillBeDuplicated ( LPCTSTR  lpszFilePath,
bool  bFullPath,
bool  bFileNameOnly = false,
int  iWhat = prAuto 
)

Checks if the filename of the given file will be duplicated in the archive, if added to the archive with the given parameters.

Parameters
lpszFilePathThe file path. You normally use it in one of the AddNewFile methods.
bFullPathThe same as CZipAddNewFileInfo::m_bFullPath.
bFileNameOnlyIf true, the method assumes that the filename is duplicated if only the name part (no path) is the same (bFullPath is ignored), otherwise the whole filename with a path is taken into account.
iWhatOne of the Predict values to interpret lpszFilePath correctly.
Returns
The zero-based index of the file in the archive which filename would be duplicated, or ZIP_FILE_INDEX_NOT_FOUND, if the filename would be unique.
bool CZipArchive::WillEncryptNextFile ( ) const
inline

Returns the value indicating whether the next file will be encrypted. To encrypt a file, a password must be set with the SetPassword method and an encryption method must be set to a value different from CZipCryptograph::encNone.

Returns
true, if the next file added to the archive will be encrypted; false otherwise.
See Also
Encryption Methods: How to Best Protect Your Data
SetEncryptionMethod
GetEncryptionMethod
SetPassword
GetPassword
void CZipArchive::WriteCentralDirectory ( bool  bFlush = true)
protected

Writes the central directory notifying a callback object if available.

bool CZipArchive::WriteNewFile ( const void *  pBuf,
DWORD  uSize 
)

Compresses the contents of the buffer and writes it to a new file.

Parameters
pBufThe buffer containing the data to be compressed and written.
uSizeThe number of bytes to be written from pBuf.
Returns
false, if the new file hasn't been opened yet; true otherwise.
See Also
Compressing Data
OpenNewFile
CloseNewFile

Member Data Documentation

bool CZipArchive::m_bAutoFinalize
protected

The value set with SetAutoFinalize().

bool CZipArchive::m_bCaseSensitive
protected

The value set with SetCaseSensitivity.

bool CZipArchive::m_bSafePaths

If true, the drive letter (or an initial path separator indicating rooted paths) is removed from the filename stored inside the archive when adding a new file to the archive or extracting an existing one. It affects AddNewFile, ExtractFile, PredictFileNameInZip, PredictExtractedFileName, WillBeDuplicated methods. Also directory traversal paths are removed from files names to prevent Zip Slip on extraction. The default value is true.

bool CZipArchive::m_bStoreFullFileTimes
protected

The value set with SetFullFileTimes

bool CZipArchive::m_bUseUtcFileTimes
protected

The value set with SetUseUtcFileTimes

ZipArchiveLib::CZipCallbackProvider CZipArchive::m_callbacks
protected

Holds currently set callback objects.

CZipCentralDir CZipArchive::m_centralDir
protected

The central directory object.

See Also
CZipCentralDir
int CZipArchive::m_iArchiveSystCompatib
protected

The value set with SetSystemCompatibility.

DWORD CZipArchive::m_iBufferSize
protected

The size of the m_pBuffer buffer. Set it before opening the archive. It is usually set with the SetAdvanced method (specify this value as the second argument).

See Also
SetAdvanced
int CZipArchive::m_iCommitMode
protected

The value set with SetCommitMode().

int CZipArchive::m_iEncryptionMethod
protected

The value set with SetEncryptionMethod.

int CZipArchive::m_iFileOpened
protected

Takes one of the CZipArchive::OpenFileType enum values.

CZipAutoBuffer CZipArchive::m_pBuffer
protected

A helper buffer used during various IO operations.

See Also
m_iBufferSize
SetAdvanced
CZipCompressor* CZipArchive::m_pCompressor
protected

The current compressor.

CZipCryptograph* CZipArchive::m_pCryptograph
protected

The current cryptograph.

CZipAutoBuffer CZipArchive::m_pszPassword
protected

The value set with SetPassword.

ZIPSTRINGCOMPARE CZipArchive::m_pZipCompare
protected

A pointer to a method used to compare strings. Can point to Compare, CompareNoCase, Collate or CollateNoCase method.

CZipStorage CZipArchive::m_storage
protected

Physical layer of the archive.

See Also
CZipStorage
CZipStringStoreSettings CZipArchive::m_stringSettings
protected

The value set with the SetStringStoreSettings() method.

CZipString CZipArchive::m_szRootPath
protected

The value set with SetRootPath().

CZipString CZipArchive::m_szTempPath
protected

The value set with SetTempPath().

WORD CZipArchive::m_uCompressionMethod
protected

The value set with SetCompressionMethod.


The documentation for this class was generated from the following file:
Back To Top Up