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

#include <ZipCompressor.h>

Inheritance diagram for CZipCompressor:
Inheritance graph

Classes

class  COffsetsArray
struct  COffsetsPair
struct  COptions
class  COptionsMap

Public Types

enum  CompressionLevel { levelDefault = 0x7FFFFFFE , levelStore = 0 , levelFastest = 1 , levelBest = 0x7FFFFFFF }
enum  CompressionMethod {
  methodStore = 0 , methodDeflate = 8 , methodBzip2 = 12 , methodZstd = 93 ,
  methodWinZipAes = 99
}
enum  CompressorType { typeDeflate = 1 , typeBzip2 , typePPMd , typeZstd }
typedef CZipArray< COffsetsPair * > CZipOffsetsPairsArray

Public Member Functions

virtual bool CanProcess (WORD uMethod)=0
virtual void Compress (const void *pBuffer, DWORD uSize)=0
virtual int CompressionLevelToNative (CompressionLevel iLevel)=0
virtual DWORD Decompress (void *pBuffer, DWORD uSize)=0
virtual void FinishCompression (bool ZIP_UNUSED bAfterException)
virtual void FinishDecompression (bool ZIP_UNUSED bAfterException)
virtual const COptionsGetOptions () const
virtual void InitCompression (int ZIP_UNUSED iLevel, CZipFileHeader *pFile, CZipCryptograph *pCryptograph)
virtual void InitDecompression (CZipFileHeader *pFile, CZipCryptograph *pCryptograph)
bool PrepareForSeek (CZipFileHeader *pCurrentFile, COffsetsPair *pPair)
void UpdateOptions (const COptionsMap &optionsMap)

Static Public Member Functions

static CZipCompressorCreateCompressor (WORD uMethod, CZipStorage *pStorage)
static bool IsCompressionSupported (WORD uCompressionMethod)

Public Attributes

ZIP_SIZE_TYPE m_uComprLeft
 The number of bytes left to compress.
DWORD m_uCrc32
 The CRC32 file checksum.
ZIP_SIZE_TYPE m_uUncomprLeft
 The number of bytes left to decompress.

Protected Member Functions

virtual int ConvertInternalError (int iErr) const
 CZipCompressor (CZipStorage *pStorage)
DWORD FillBuffer ()
void FlushWriteBuffer ()
void InitBuffer ()
void ReleaseBuffer ()
void ThrowError (int iErr, bool bInternal=false)
void UpdateCrc (const void *pBuffer, DWORD uSize)
void UpdateFileCrc (const void *pBuffer, DWORD uSize)
virtual void UpdateOptions (const COptions *ZIP_UNUSED pOptions)
void WriteBuffer (char *pBuffer, DWORD uSize)

Protected Attributes

CZipAutoBuffer m_pBuffer
 A buffer that receives compressed data or provides data for decompression.
CZipCryptographm_pCryptograph
 The current cryptograph.
CZipFileHeaderm_pFile
 The file header being compressed or decompressed.
CZipStoragem_pStorage
 The current storage object.

Detailed Description

A base class for compressors used in compression and decompression of data.

Member Typedef Documentation

◆ CZipOffsetsPairsArray

Array type for storing offset pairs.

See also
COffsetsPair

Member Enumeration Documentation

◆ CompressionLevel

The compression level.

Enumerator
levelDefault 

The default compression level (translates to 6 for deflate and bzip2 and to ZSTD_CLEVEL_DEFAULT for ZSTD compression).

levelStore 

No compression used. Data is stored.

levelFastest 

The fastest compression. The compression ratio is the lowest (apart from levelStore).

levelBest 

The highest compression ratio. It's usually the slowest one. Note, the maximum number for ZSTD compression is larger than for other compressors (defined by ZSTD_MAX_CLEVEL).

◆ CompressionMethod

The compression method.

Enumerator
methodStore 

A file is stored, not compressed.

methodDeflate 

The deflate compression method.

methodBzip2 

The bzip2 compression method.

See also
Compressing Data
methodZstd 

The Zstandard (zstd) compression method.

See also
Compressing Data
methodWinZipAes 

This value means that WinZip AES encryption is used. The original compression method is stored in a WinZip extra field. It is only an informational value - you cannot set it as a compression method. The ZipArchive Library handles this value internally.

See also
Encryption Methods: How to Best Protect Your Data

◆ CompressorType

The type of a compressor.

Enumerator
typeDeflate 

Deflate compression (default in zip archives).

typeBzip2 

Bzip2 compression.

typePPMd 

PPMd compression.

typeZstd 

ZSTD compression.

Constructor & Destructor Documentation

◆ CZipCompressor()

CZipCompressor::CZipCompressor ( CZipStorage * pStorage)
inlineprotected

Initializes a new instance of the CZipCompressor class.

Parameters
pStorageThe current storage object.

Member Function Documentation

◆ CanProcess()

virtual bool CZipCompressor::CanProcess ( WORD uMethod)
pure virtual

Returns the value indicating whether the current CZipCompressor object supports the given compression method.

Parameters
uMethodThe compression method. It can be one of the CompressionMethod values.
Returns
true, if the compression method is supported; false otherwise.

Implemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ Compress()

virtual void CZipCompressor::Compress ( const void * pBuffer,
DWORD uSize )
pure virtual

Compresses the given data.

Parameters
pBufferThe buffer that holds the data to compress.
uSizeThe size of pBuffer.
See also
InitCompression
FinishCompression

Implemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ CompressionLevelToNative()

virtual int CZipCompressor::CompressionLevelToNative ( CompressionLevel iLevel)
pure virtual

Converts a generic compression level to the compressor's native level.

Parameters
iLevelThe generic compression level.
Returns
The native compression level for this compressor.

Implemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ ConvertInternalError()

virtual int CZipCompressor::ConvertInternalError ( int iErr) const
inlineprotectedvirtual

Converts an internal error code of the compressor to the ZipArchive Library error code.

Parameters
iErrAn internal error code.
Returns
A ZipArchive Library error code.

Reimplemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ CreateCompressor()

CZipCompressor * CZipCompressor::CreateCompressor ( WORD uMethod,
CZipStorage * pStorage )
static

A factory method that creates an appropriate compressor for the given compression method.

Parameters
uMethodThe compression method to create a compressor for. It can be one of the CompressionMethod values.
pStorageThe current storage object.

◆ Decompress()

virtual DWORD CZipCompressor::Decompress ( void * pBuffer,
DWORD uSize )
pure virtual

Decompresses the given data.

Parameters
pBufferThe buffer that receives the decompressed data.
uSizeThe size of pBuffer.
Returns
The number of bytes decompressed and written to pBuffer.
Note
This method should be called repeatedly until it returns 0.
See also
InitDecompression
FinishDecompression

Implemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ FillBuffer()

DWORD CZipCompressor::FillBuffer ( )
inlineprotected

Fills the read buffer.

Returns
The number of bytes read.

◆ FinishCompression()

virtual void CZipCompressor::FinishCompression ( bool ZIP_UNUSED bAfterException)
inlinevirtual

The method called at the end of the compression process.

Parameters
bAfterExceptionSet to true, if an exception occurred before or to false otherwise.
See also
InitCompression
Compress

◆ FinishDecompression()

virtual void CZipCompressor::FinishDecompression ( bool ZIP_UNUSED bAfterException)
inlinevirtual

The method called at the end of the decompression process.

Parameters
bAfterExceptionSet to true, if an exception occurred before or to false otherwise.
See also
InitDecompression
Decompress

◆ FlushWriteBuffer()

void CZipCompressor::FlushWriteBuffer ( )
inlineprotected

Flushes data in the buffer into the storage, encrypting the data if needed.

◆ GetOptions()

virtual const COptions * CZipCompressor::GetOptions ( ) const
inlinevirtual

Returns the current options of the compressor.

Returns
The current options for the compressor.
See also
Compressing Data
CZipArchive::SetCompressionOptions
UpdateOptions

Reimplemented in ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ InitBuffer()

void CZipCompressor::InitBuffer ( )
protected

Initializes the internal buffer.

See also
ReleaseBuffer

◆ InitCompression()

virtual void CZipCompressor::InitCompression ( int ZIP_UNUSED iLevel,
CZipFileHeader * pFile,
CZipCryptograph * pCryptograph )
inlinevirtual

The method called when a new file is opened for compression.

Parameters
iLevelThe compression level. Use numeric values here, not CZipCompressor::CompressionLevel values.
pFileThe file being compressed.
pCryptographThe current CZipCryptograph. It can be NULL, if no encryption is used.
See also
Compress
FinishCompression

◆ InitDecompression()

virtual void CZipCompressor::InitDecompression ( CZipFileHeader * pFile,
CZipCryptograph * pCryptograph )
inlinevirtual

The method called when a new file is opened for extraction.

Parameters
pFileThe file being extracted.
pCryptographThe current CZipCryptograph. It can be NULL, if no decryption is used.
See also
Decompress
FinishDecompression

Reimplemented in ZipArchiveLib::CBaseLibCompressor, ZipArchiveLib::CBzip2Compressor, ZipArchiveLib::CDeflateCompressor, and ZipArchiveLib::CZstdCompressor.

◆ IsCompressionSupported()

bool CZipCompressor::IsCompressionSupported ( WORD uCompressionMethod)
inlinestatic

Returns the value indicating whether the given compression method is supported by the ZipArchive Library.

Parameters
uCompressionMethodThe compression method. It can be one of the CompressionMethod values.
Returns
true, if the compression method is supported, false otherwise.

◆ PrepareForSeek()

bool CZipCompressor::PrepareForSeek ( CZipFileHeader * pCurrentFile,
COffsetsPair * pPair )

Prepares the compressor for the seeking operation.

Parameters
pCurrentFileThe currently opened file.
pPairThe offsets pair describing the seek location.
See also
Creating Seekable Compressed Data

◆ ReleaseBuffer()

void CZipCompressor::ReleaseBuffer ( )
inlineprotected

Releases the internal buffer.

See also
InitBuffer

◆ ThrowError()

void CZipCompressor::ThrowError ( int iErr,
bool bInternal = false )
inlineprotected

Throws an exception with a given error code.

Parameters
iErrAn error code.
bInternaltrue, if iErr is an internal error code and needs a conversion to the ZipArchive Library error code; false otherwise.
See also
ConvertInternalError

◆ UpdateCrc()

void CZipCompressor::UpdateCrc ( const void * pBuffer,
DWORD uSize )
protected

Updates CRC value while decompression.

Parameters
pBufferA buffer with data for which the CRC value should be updated.
uSizeThe size of the buffer.

◆ UpdateFileCrc()

void CZipCompressor::UpdateFileCrc ( const void * pBuffer,
DWORD uSize )
protected

Updates CRC value while compression.

Parameters
pBufferA buffer with data for which the CRC value should be updated.
uSizeThe size of the buffer.

◆ UpdateOptions() [1/2]

virtual void CZipCompressor::UpdateOptions ( const COptions *ZIP_UNUSED pOptions)
inlineprotectedvirtual

Updates the current options with the new options.

Parameters
pOptionsThe new options to apply.

◆ UpdateOptions() [2/2]

void CZipCompressor::UpdateOptions ( const COptionsMap & optionsMap)

Updates the current options with the options stored in optionsMap, if the appropriate options are present in the map.

Parameters
optionsMapThe map to get the new options from.
See also
Compressing Data
GetOptions

◆ WriteBuffer()

void CZipCompressor::WriteBuffer ( char * pBuffer,
DWORD uSize )
inlineprotected

Writes the buffer into the storage, encrypting the data if needed.

Parameters
pBufferThe buffer with data to write.
uSizeThe size of the buffer.

Member Data Documentation

◆ m_pBuffer

CZipAutoBuffer CZipCompressor::m_pBuffer
protected

A buffer that receives compressed data or provides data for decompression.

◆ m_pCryptograph

CZipCryptograph* CZipCompressor::m_pCryptograph
protected

The current cryptograph.

◆ m_pFile

CZipFileHeader* CZipCompressor::m_pFile
protected

The file header being compressed or decompressed.

◆ m_pStorage

CZipStorage* CZipCompressor::m_pStorage
protected

The current storage object.

◆ m_uComprLeft

ZIP_SIZE_TYPE CZipCompressor::m_uComprLeft

The number of bytes left to compress.

◆ m_uCrc32

DWORD CZipCompressor::m_uCrc32

The CRC32 file checksum.

◆ m_uUncomprLeft

ZIP_SIZE_TYPE CZipCompressor::m_uUncomprLeft

The number of bytes left to decompress.


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