ZipArchiveLib
namespace as provided in the sample code below.
To create seekable compressed data, you need to set the appropriate option for the
ZipArchiveLib::CDeflateCompressor compressor before
compressing a file. The option responsible for controlling creation of synchronization
blocks is the
ZipArchiveLib::CDeflateCompressor::COptions::m_iSyncRatio
member variable. It determines how often the synchronization blocks are created.
See Compressing Data for some more information about
setting compressors options.
Immediately after a file is compressed, you can retrieve the array of the offsets
pairs that describe the location of synchronization blocks and corresponding offsets
in uncompressed data. Use the ZipArchiveLib::CDeflateCompressor::GetOffsetsArray()
method for that. You should save the array returned by this method to a buffer,
because the next compression operation will invalidate this object (also the next
decompression operation may invalidate it). You can use the CZipCompressor::COffsetsArray::Save()
method for that. You will need this array when you will be performing seeking in
the compressed data later.
CZipCompressor::COffsetsArray::GetStatistics()
method to gather information about block sizes. You can then adjust the
ZipArchiveLib::CDeflateCompressor::COptions::m_iSyncRatio
value and see how the block sizes change with respect to the compression ratio
To perform seeking in compressed data, you will need an offsets array (CZipCompressor::COffsetsArray
)
created during compression. You can load previously saved array with the CZipCompressor::COffsetsArray::Load()
method.
Retrieve the desired offsets pair (CZipCompressor::COffsetsPair
)
from the array and use it as an argument to one of the CZipArchive::ExtractFile()
methods.
The seeking operation causes CRC value to be ignored while decompressing data. It has the same effect as calling the CZipArchive::SetIgnoredConsistencyChecks() method with the CZipArchive::checkLocalCRC argument for the current file.
CZipArchive::SeekInFile()
method and then you
can start decompressing a file with calls to the CZipArchive::ReadFile()
method.
The offsets array (CZipCompressor::COffsetsArray
) created
during compressing data is necessary when decompressing data, because it contains
locations of synchronizations blocks and the decompression can start only from those
blocks. You can preserve this array in multiple ways (e.g. as a file in archive
or inside another file). One way is to store the array for a particular file in
central extra data of this file. For more information about using extra data, please
refer to Providing Custom Data: Extra Fields. It is recommended that you use
the ZIP_EXTRA_ZARCH_SEEK identifier for extra data.
To save an offsets array to a buffer or to load an array from a buffer, use the
corresponding method:
CZipCompressor::COffsetsArray::Save()
CZipCompressor::COffsetsArray::Load()
When saving, the offsets array tries to use 4 bytes for offsets. However, when any of the offsets does not fit into 4 bytes then 8 bytes are automatically used for each of the offsets. When loading, the library automatically detects the number of bytes used previously during saving. To use 8 bytes for offsets, the ZipArchive Library must be compiled with the Zip64 support (see Zip64 Format: Crossing the Limits of File Sizes and Number of Files and Segments for more information about Zip64 support).
ZipArchiveLib::CDeflateCompressor::COptions::m_iSyncRatio
ZipArchiveLib::CDeflateCompressor::GetOffsetsArray()
CZipCompressor::COffsetsArray::GetStatistics()
CZipCompressor::COffsetsArray::Save()
CZipCompressor::COffsetsArray::Load()
CZipArchive::SeekInFile()