CZipCompression Class Reference
[Compression]

Search Toolkit Book for CZipCompression

#include <zlib.hpp>

Inheritance diagram for CZipCompression:

Inheritance graph
[legend]
Collaboration diagram for CZipCompression:

Collaboration graph
[legend]
List of all members.

Detailed Description

CZipCompression --.

Define a base methods for compression/decompression memory buffers and files.

Definition at line 107 of file zlib.hpp.

Public Types

enum  EFlags { fAllowTransparentRead = (1<<0), fCheckFileHeader = (1<<1), fWriteGZipFormat = (1<<2), fRestoreFileAttr = (1<<3) }
 Compression/decompression flags. More...

Public Member Functions

 CZipCompression (ELevel level=eLevel_Default, int window_bits=kZlibDefaultWbits, int mem_level=kZlibDefaultMemLevel, int strategy=kZlibDefaultStrategy)
 Constructor.
virtual ~CZipCompression (void)
 Destructor.
virtual CVersionInfo GetVersion (void) const
 Return name and version of the compression library.
virtual ELevel GetDefaultLevel (void) const
 Returns default compression level for a compression algorithm.
virtual bool CompressBuffer (const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len)
 Compress data in the buffer.
virtual bool DecompressBuffer (const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len)
 Compress data in the buffer.
long EstimateCompressionBufferSize (size_t src_len)
 Estimate buffer size for data compression.
virtual bool CompressFile (const string &src_file, const string &dst_file, size_t buf_size=kCompressionDefaultBufSize)
 Compress file.
virtual bool DecompressFile (const string &src_file, const string &dst_file, size_t buf_size=kCompressionDefaultBufSize)
 Decompress file.
virtual bool DecompressFileIntoDir (const string &src_file, const string &dst_dir, size_t buf_size=kCompressionDefaultBufSize)
 Decompress file into specified directory.

Protected Member Functions

string FormatErrorMessage (string where, bool use_stream_data=true) const
 Format string with last error description.

Protected Attributes

void * m_Stream
 Compressor stream.
int m_WindowBits
 The base two logarithm of the window size (the size of the history buffer).
int m_MemLevel
 The allocation memory level for the internal compression state.
int m_Strategy
 The parameter to tune compression algorithm.

Classes

struct  SFileInfo
 Structure to keep compressed file information. More...


Member Enumeration Documentation

enum CZipCompression::EFlags
 

Compression/decompression flags.

Enumerator:
fAllowTransparentRead  Allow transparent reading data from buffer/file/stream regardless is it compressed or not. Check (and skip) file header for decompression stream.

But be aware, if data source contains broken data and API cannot detect that it is compressed data, that you can get binary instead of decompressed data. By default this flag is OFF. NOTE: zlib v1.1.4 and earlier have a bug in decoding. In some cases decompressor can produce output data on invalid compressed data. So, this is not recommended to use this flag with old zlib versions.

fCheckFileHeader  Use gzip (.gz) file format to write into compression stream (the archive also can store file name and file modification date in this format).
fWriteGZipFormat  This flag can be used only with DecompressFile[IntoDir]().

It allow to restore the original file name and/or time stamp stored in the file header, if present.

See also:
DecompressFile, DecompressFileIntoDir
fRestoreFileAttr 

Definition at line 111 of file zlib.hpp.


Constructor & Destructor Documentation

CZipCompression::CZipCompression ELevel  level = eLevel_Default,
int  window_bits = kZlibDefaultWbits,
int  mem_level = kZlibDefaultMemLevel,
int  strategy = kZlibDefaultStrategy
 

Constructor.

Definition at line 86 of file zlib.cpp.

References DEF_MEM_LEVEL, kZlibDefaultMemLevel, kZlibDefaultStrategy, kZlibDefaultWbits, m_MemLevel, m_Strategy, m_Stream, m_WindowBits, MAX_WBITS, and Z_DEFAULT_STRATEGY.

CZipCompression::~CZipCompression void   )  [virtual]
 

Destructor.

Definition at line 105 of file zlib.cpp.

References STREAM.


Member Function Documentation

bool CZipCompression::CompressBuffer const void *  src_buf,
size_t  src_len,
void *  dst_buf,
size_t  dst_size,
size_t *  dst_len
[virtual]
 

Compress data in the buffer.

Altogether, the total size of the destination buffer must be little more then size of the source buffer.

Parameters:
src_buf Source buffer.
src_len Size of data in source buffer.
dst_buf Destination buffer.
dst_size Size of destination buffer.
dst_len Size of compressed data in destination buffer.
Returns:
Return TRUE if operation was succesfully or FALSE otherwise. On success, 'dst_buf' contains compressed data of dst_len size.
See also:
EstimateCompressionBufferSize, DecompressBuffer

Implements ICompression.

Definition at line 274 of file zlib.cpp.

References crc32(), deflate(), deflateEnd(), deflateInit2_(), ERR_COMPRESS, F_ISSET, FormatErrorMessage(), fWriteGZipFormat, CCompression::GetLevel(), kMax_UInt, LIMIT_SIZE_PARAM_U, m_MemLevel, m_Strategy, m_WindowBits, s_WriteGZipFooter(), s_WriteGZipHeader(), CCompression::SetError(), STREAM, Z_BUF_ERROR, Z_DEFLATED, Z_FINISH, Z_OK, Z_STREAM_END, Z_STREAM_ERROR, zError(), and ZLIB_VERSION.

Referenced by CId2Compressor::CompressChunk(), and CPdfObject::x_PrintTo().

bool CZipCompression::CompressFile const string &  src_file,
const string &  dst_file,
size_t  buf_size = kCompressionDefaultBufSize
[virtual]
 

Compress file.

Parameters:
src_file File name of source file.
dst_file File name of result file.
buf_size Buffer size used to read/write files.
Returns:
Return TRUE on success, FALSE on error.
See also:
DecompressFile, DecompressFileIntoDir
Note:
This method, as well as some gzip utilities, always keeps the original file name and timestamp in the compressed file. On this moment DecompressFile() do not use original file name at all, but be aware... If you assign different base name to destination compressed file, that behavior of decompression utilities on different platforms may differ. For example, WinZip on MS Windows always restore original file name and timestamp stored in the file. UNIX gunzip have -N option for this, but by default do not use it, and just creates a decompressed file with the name of the compressed file without .gz extention.

Implements ICompression.

Definition at line 493 of file zlib.cpp.

References CCompressionFile::eMode_Write, CCompression::GetFlags(), CCompression::GetLevel(), m_MemLevel, m_Strategy, m_WindowBits, CZipCompressionFile::Open(), s_CollectFileInfo(), and CCompression::SetFlags().

bool CZipCompression::DecompressBuffer const void *  src_buf,
size_t  src_len,
void *  dst_buf,
size_t  dst_size,
size_t *  dst_len
[virtual]
 

Compress data in the buffer.

Altogether, the total size of the destination buffer must be little more then size of the source buffer.

Parameters:
src_buf Source buffer.
src_len Size of data in source buffer.
dst_buf Destination buffer.
dst_size Size of destination buffer.
dst_len Size of compressed data in destination buffer.
Returns:
Return TRUE if operation was succesfully or FALSE otherwise. On success, 'dst_buf' contains compressed data of dst_len size.
See also:
CompressBuffer

Implements ICompression.

Definition at line 372 of file zlib.cpp.

References ERR_COMPRESS, F_ISSET, fAllowTransparentRead, fCheckFileHeader, FormatErrorMessage(), inflate(), inflateEnd(), inflateInit2_(), kMax_UInt, LIMIT_SIZE_PARAM_U, m_WindowBits, s_CheckGZipHeader(), CCompression::SetError(), STREAM, Z_BUF_ERROR, Z_FINISH, Z_OK, Z_STREAM_END, Z_STREAM_ERROR, zError(), and ZLIB_VERSION.

bool CZipCompression::DecompressFile const string &  src_file,
const string &  dst_file,
size_t  buf_size = kCompressionDefaultBufSize
[virtual]
 

Decompress file.

Parameters:
src_file File name of source file.
dst_file File name of result file.
buf_size Buffer size used to read/write files.
Returns:
Return TRUE on success, FALSE on error.
See also:
CompressFile, DecompressFileIntoDir
Note:
CompressFile() method, as well as some gzip utilities, always keeps the original file name and timestamp in the compressed file. If fRestoreFileAttr flag is set, that time stamp, stored in the file header will be restored. The original file name cannot be restored here, see DecompressFileIntoDir().

Implements ICompression.

Definition at line 526 of file zlib.cpp.

References CCompressionFile::eMode_Read, F_ISSET, fRestoreFileAttr, CCompression::GetFlags(), CCompression::GetLevel(), m_MemLevel, m_Strategy, m_WindowBits, CZipCompression::SFileInfo::name, CZipCompressionFile::Open(), and CCompression::SetFlags().

bool CZipCompression::DecompressFileIntoDir const string &  src_file,
const string &  dst_dir,
size_t  buf_size = kCompressionDefaultBufSize
[virtual]
 

Decompress file into specified directory.

Parameters:
src_file File name of source file.
dst_dir Destination directory.
buf_size Buffer size used to read/write files.
Returns:
Return TRUE on success, FALSE on error.
See also:
CompressFile, DecompressFile
Note:
CompressFile() method, as well as some gzip utilities, always keeps the original file name and timestamp in the compressed file. If fRestoreFileAttr flag is set, that original file name and time stamp, stored in the file header will be restored. If not, that destination file will be named as archive name without extention.

Definition at line 570 of file zlib.cpp.

References CCompressionFile::eMode_Read, F_ISSET, fRestoreFileAttr, CCompression::GetFlags(), CCompression::GetLevel(), m_MemLevel, m_Strategy, m_WindowBits, CDirEntry::MakePath(), CZipCompression::SFileInfo::name, CZipCompressionFile::Open(), CCompression::SetFlags(), and CDirEntry::SplitPath().

long CZipCompression::EstimateCompressionBufferSize size_t  src_len  ) 
 

Estimate buffer size for data compression.

The function shall estimate the size of buffer required to compress specified number of bytes of data using the CompressBuffer() function. This function may return a conservative value that may be larger than 'src_len'.

Parameters:
src_len Size of compressed data.
Returns:
Estimated buffer size. Return -1 on error, or if this method is not supported by current version of the zlib library.
See also:
CompressBuffer

Definition at line 463 of file zlib.cpp.

References deflateBound(), deflateEnd(), deflateInit2_(), F_ISSET, fWriteGZipFormat, CCompression::GetLevel(), m_MemLevel, m_Strategy, m_WindowBits, CCompression::SetError(), STREAM, Z_DEFLATED, Z_OK, zError(), and ZLIB_VERSION.

string CZipCompression::FormatErrorMessage string  where,
bool  use_stream_data = true
const [protected]
 

Format string with last error description.

Definition at line 624 of file zlib.cpp.

References CCompression::GetErrorCode(), CCompression::GetErrorDescription(), NStr::IntToString(), STREAM, and NStr::UIntToString().

Referenced by CompressBuffer(), DecompressBuffer(), CZipDecompressor::End(), CZipCompressor::End(), CZipCompressor::Finish(), CZipCompressor::Flush(), CZipDecompressor::Init(), CZipCompressor::Init(), CZipDecompressor::Process(), and CZipCompressor::Process().

virtual ELevel CZipCompression::GetDefaultLevel void   )  const [inline, virtual]
 

Returns default compression level for a compression algorithm.

Implements ICompression.

Definition at line 150 of file zlib.hpp.

References kZlibDefaultCompression.

CVersionInfo CZipCompression::GetVersion void   )  const [virtual]
 

Return name and version of the compression library.

Implements CCompression.

Definition at line 268 of file zlib.cpp.

References ZLIB_VERSION.


Member Data Documentation

int CZipCompression::m_MemLevel [protected]
 

The allocation memory level for the internal compression state.

Definition at line 320 of file zlib.hpp.

Referenced by CompressBuffer(), CompressFile(), CZipCompression(), DecompressFile(), DecompressFileIntoDir(), EstimateCompressionBufferSize(), and CZipCompressor::Init().

int CZipCompression::m_Strategy [protected]
 

The parameter to tune compression algorithm.

Definition at line 322 of file zlib.hpp.

Referenced by CompressBuffer(), CompressFile(), CZipCompression(), DecompressFile(), DecompressFileIntoDir(), EstimateCompressionBufferSize(), and CZipCompressor::Init().

void* CZipCompression::m_Stream [protected]
 

Compressor stream.

Definition at line 317 of file zlib.hpp.

Referenced by CZipCompression().

int CZipCompression::m_WindowBits [protected]
 

The base two logarithm of the window size (the size of the history buffer).

Definition at line 318 of file zlib.hpp.

Referenced by CompressBuffer(), CompressFile(), CZipCompression(), DecompressBuffer(), DecompressFile(), DecompressFileIntoDir(), EstimateCompressionBufferSize(), CZipDecompressor::Init(), CZipCompressor::Init(), and CZipDecompressor::Process().


The documentation for this class was generated from the following files:
Generated on Thu Sep 4 03:10:44 2008 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Thu Sep 04 03:26:14 2008 by modify_doxy.py rev. 117643