CBZip2Compression Class Reference
[Compression]

Search Toolkit Book for CBZip2Compression

#include <bzip2.hpp>

Inheritance diagram for CBZip2Compression:

Inheritance graph
[legend]
Collaboration diagram for CBZip2Compression:

Collaboration graph
[legend]
List of all members.

Detailed Description

CBZip2Compression --.

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

Definition at line 90 of file bzip2.hpp.

Public Types

typedef CBZip2Compression::TFlags TBZip2Flags
 Bitwise OR of EFlags.
enum  EFlags { fAllowTransparentRead = (1<<0) }
 Compression/decompression flags. More...

Public Member Functions

 CBZip2Compression (ELevel level=eLevel_Default, int verbosity=0, int work_factor=0, int small_decompress=0)
 Constructor.
virtual ~CBZip2Compression (void)
 Destructor.
virtual CVersionInfo GetVersion (void) const
 Return name and version of the compression library.
virtual ELevel GetLevel (void) const
 Get compression level.
virtual ELevel GetDefaultLevel (void) const
 Return 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)
 Decompress data in the buffer.
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.

Protected Member Functions

const char * GetBZip2ErrorDescription (int errcode)
 Get error description for specified error code.
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_Verbosity
 Verbose monitoring/debugging output level.
int m_WorkFactor
 See description above.
int m_SmallDecompress
 Use memory-frugal decompression algorithm.


Member Typedef Documentation

typedef CBZip2Compression::TFlags CBZip2Compression::TBZip2Flags
 

Bitwise OR of EFlags.

Definition at line 102 of file bzip2.hpp.


Member Enumeration Documentation

enum CBZip2Compression::EFlags
 

Compression/decompression flags.

Enumerator:
fAllowTransparentRead  Allow transparent reading data from buffer/file/stream regardless is it compressed or not.

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.

Definition at line 94 of file bzip2.hpp.


Constructor & Destructor Documentation

CBZip2Compression::CBZip2Compression ELevel  level = eLevel_Default,
int  verbosity = 0,
int  work_factor = 0,
int  small_decompress = 0
 

Constructor.

Definition at line 60 of file bzip2.cpp.

References m_Stream.

CBZip2Compression::~CBZip2Compression void   )  [virtual]
 

Destructor.

Definition at line 74 of file bzip2.cpp.

References STREAM.


Member Function Documentation

bool CBZip2Compression::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 [in] Source buffer.
src_len [in] Size of data in source buffer.
dst_buf [in] Destination buffer.
dst_size [in] Size of destination buffer.
dst_len [out] 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:
DecompressBuffer

Implements ICompression.

Definition at line 98 of file bzip2.cpp.

References BZ2_bzBuffToBuffCompress(), BZ_OK, BZ_PARAM_ERROR, ERR_COMPRESS, FormatErrorMessage(), GetBZip2ErrorDescription(), GetLevel(), kMax_UInt, LIMIT_SIZE_PARAM_U, and CCompression::SetError().

bool CBZip2Compression::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

Implements ICompression.

Definition at line 189 of file bzip2.cpp.

References CCompressionFile::eMode_Write, CCompression::GetErrorCode(), CCompression::GetErrorDescription(), CCompression::GetFlags(), GetLevel(), m_SmallDecompress, m_Verbosity, m_WorkFactor, CBZip2CompressionFile::Open(), CCompression::SetError(), and CCompression::SetFlags().

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

Decompress data in the buffer.

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

Implements ICompression.

Definition at line 140 of file bzip2.cpp.

References BZ2_bzBuffToBuffDecompress(), BZ_DATA_ERROR, BZ_DATA_ERROR_MAGIC, BZ_OK, BZ_PARAM_ERROR, ERR_COMPRESS, F_ISSET, fAllowTransparentRead, FormatErrorMessage(), GetBZip2ErrorDescription(), kMax_UInt, LIMIT_SIZE_PARAM_U, and CCompression::SetError().

bool CBZip2Compression::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

Implements ICompression.

Definition at line 217 of file bzip2.cpp.

References CCompressionFile::eMode_Read, CCompression::GetErrorCode(), CCompression::GetErrorDescription(), CCompression::GetFlags(), GetLevel(), m_SmallDecompress, m_Verbosity, m_WorkFactor, CBZip2CompressionFile::Open(), CCompression::SetError(), and CCompression::SetFlags().

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

Format string with last error description.

Definition at line 269 of file bzip2.cpp.

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

Referenced by CBZip2CompressionFile::Close(), CompressBuffer(), DecompressBuffer(), CBZip2Decompressor::End(), CBZip2Compressor::End(), CBZip2Compressor::Finish(), CBZip2Compressor::Flush(), CBZip2Decompressor::Init(), CBZip2Compressor::Init(), CBZip2CompressionFile::Open(), CBZip2Decompressor::Process(), CBZip2Compressor::Process(), CBZip2CompressionFile::Read(), and CBZip2CompressionFile::Write().

const char * CBZip2Compression::GetBZip2ErrorDescription int  errcode  )  [protected]
 

Get error description for specified error code.

Definition at line 247 of file bzip2.cpp.

Referenced by CBZip2CompressionFile::Close(), CompressBuffer(), DecompressBuffer(), CBZip2Compressor::End(), CBZip2Compressor::Finish(), CBZip2Compressor::Flush(), CBZip2Decompressor::Init(), CBZip2Compressor::Init(), CBZip2CompressionFile::Open(), CBZip2Decompressor::Process(), CBZip2Compressor::Process(), CBZip2CompressionFile::Read(), and CBZip2CompressionFile::Write().

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

Return default compression level for a compression algorithm.

Implements ICompression.

Definition at line 126 of file bzip2.hpp.

References ICompression::eLevel_VeryHigh.

CCompression::ELevel CBZip2Compression::GetLevel void   )  const [virtual]
 

Get compression level.

NOTE: BZip2 algorithm do not support zero level compression. So the "eLevel_NoCompression" will be translated to "eLevel_Lowest".

Reimplemented from CCompression.

Definition at line 87 of file bzip2.cpp.

References ICompression::eLevel_Lowest, ICompression::eLevel_NoCompression, and CCompression::GetLevel().

Referenced by CompressBuffer(), CompressFile(), DecompressFile(), CBZip2Compressor::Init(), and CBZip2CompressionFile::Open().

CVersionInfo CBZip2Compression::GetVersion void   )  const [virtual]
 

Return name and version of the compression library.

Implements CCompression.

Definition at line 81 of file bzip2.cpp.

References BZ2_bzlibVersion().


Member Data Documentation

int CBZip2Compression::m_SmallDecompress [protected]
 

Use memory-frugal decompression algorithm.

Definition at line 228 of file bzip2.hpp.

Referenced by CompressFile(), DecompressFile(), CBZip2Decompressor::Init(), and CBZip2CompressionFile::Open().

void* CBZip2Compression::m_Stream [protected]
 

Compressor stream.

Definition at line 225 of file bzip2.hpp.

Referenced by CBZip2Compression().

int CBZip2Compression::m_Verbosity [protected]
 

Verbose monitoring/debugging output level.

Definition at line 226 of file bzip2.hpp.

Referenced by CompressFile(), DecompressFile(), CBZip2Decompressor::Init(), CBZip2Compressor::Init(), and CBZip2CompressionFile::Open().

int CBZip2Compression::m_WorkFactor [protected]
 

See description above.

Definition at line 227 of file bzip2.hpp.

Referenced by CompressFile(), DecompressFile(), CBZip2Compressor::Init(), and CBZip2CompressionFile::Open().


The documentation for this class was generated from the following files:
Generated on Mon Dec 7 10:34:29 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:22:46 2009 by modify_doxy.py rev. 173732