You should call CZipArchive::Close() after you have finished working with an archive. To read
how to safely close an archive if an exception was thrown while processing an archive, see Exceptions Handling.

If you find that the ZipArchive Library does not extract all files from the archive created by external software, then most
probably an incorrect number of files is written in the archive itself. To deal with this situation, try using the CZipArchive::SetSpecialFlags() method with the CZipArchive::sfExhaustiveRead
flag.

by calling it once using the uncompressed size (CZipFileHeader::m_uUncomprSize) and checking
that the same value is returned by this method. To make sure that the decompression was correct, you may call this method
once more, to ensure that it returns 0.

Examine the return value from this method to ensure that the extraction process was successful. It should equal to
1.

If an exception was thrown while extracting data, call this method with the bAfterException parameter set to
true, to prevent further exceptions being thrown when closing.

Sample Code

CZipArchive zip;

// open an existing archive

zip.Open(_T("C:\\Temp\\test.zip"));

// open the first file in the archive for extraction

zip.OpenFile(0);

// for the simplicity of this example assume

// that the uncompressed size fits into the DWORD type

DWORD uSize = (DWORD)zip[0]->m_uUncomprSize;

CZipAutoBuffer buffer;

buffer.Allocate(uSize);

try

{

// decompress data

if (zip.ReadFile(buffer, uSize) != uSize)

CZipException::Throw();

char temp;

// check if all the data was decompressed

if (zip.ReadFile(&temp, 1) != 0)

// there is more data to decompress than declared

// this is an invalid zip archive

CZipException::Throw();

// check the return code to ensure that the extraction was

// successful

if (zip.CloseFile() != 1)

CZipException::Throw();

zip.Close();

// write the extracted file to the disk

CZipFile file;

file.Open(_T("C:\\Temp\\file.out"),

CZipFile::modeCreate | CZipFile::modeWrite, true);

file.Write(buffer, uSize);

}

// a simplified exception handler

catch(...)

{

zip.Close(CZipArchive::afAfterException);

throw;

}

Shared and Multithreaded Extraction

You can share one copy of the central directory between multiple CZipArchive objects that refer
to the same archive. You can then open the same archive from multiple threads and perform read operations (such as extracting
or testing) minimizing this way memory usage and improving the performance (the central directory is read only once from
the disk). To benefit from this feature, perform the following steps:

Additional Considerations

You need to make sure that _ZIP_USE_LOCKING is defined in the _features.h
file to ensure a proper locking mechanism in multithreaded operations. It is not defined by default.

The shared central directory keeps a reference count how many times it is used. Therefore, you don't have to open all subsequent
archives from the first object and you don't have to keep the first object opened all the time. You only need to make sure,
that the archive object you open from is opened. When the last of the CZipArchive objects sharing
the same central directory is destroyed, the central directory is removed from memory.