📄 proc_zlib.cpp
字号:
/*
** CPQDIF_SP_ZLIB class. Implements a compression processor for the ZLIB
** compression library. See PQDIF documentation for details.
** --------------------------------------------------------------------------
**
** File name: $Workfile: proc_zlib.cpp $
** Last modified: $Modtime: 3/24/98 10:43a $
** Last modified by: $Author: Rob $
**
** VCS archive path: $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/proc_zlib.cpp $
** VCS revision: $Revision: 5 $
*/
#include "PQDIF_classes.h"
// Public-domain ZLIB code
#include "zlib.h"
// Construction
// ============
CPQDIF_SP_ZLIB::CPQDIF_SP_ZLIB()
{
// Allocate input buffer
AllocateBuffer( 16384 );
// Allocate output buffer
m_sizeOutput = 16384;
m_bufferOutput = new BYTE[ m_sizeOutput ];
}
CPQDIF_SP_ZLIB::~CPQDIF_SP_ZLIB()
{
delete [] m_bufferOutput;
}
bool CPQDIF_SP_ZLIB::StreamEncode( void )
{
bool status = TRUE;
bool haveData = FALSE;
long sizeActual = 0;
z_stream c_stream; /* compression stream */
int err;
// Init ZLIB for best compression ratio
memset( &c_stream, 0, sizeof( c_stream ) );
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit( &c_stream, Z_BEST_COMPRESSION );
// Init output buffer
c_stream.next_out = m_bufferOutput;
c_stream.avail_out = m_sizeOutput;
c_stream.total_out = 0;
do
{
// Fill up the input buffer?
if( c_stream.avail_in == 0 )
{
haveData = m_pstrm->ProcessRead( m_buffer, m_maxBuffer, sizeActual );
// End of data?
if( !haveData )
break;
c_stream.next_in = m_buffer;
c_stream.avail_in = sizeActual;
}
// Compress!
err = deflate( &c_stream, Z_NO_FLUSH );
// Flush output buffer?
if( c_stream.total_out > 0 )
{
// Suck up what's in there
m_checksum = adler32( m_checksum, (const Bytef *) m_bufferOutput, c_stream.total_out );
status = m_pstrm->ProcessWrite( m_bufferOutput, c_stream.total_out );
// Re-init the output buffer
c_stream.next_out = m_bufferOutput;
c_stream.avail_out = m_sizeOutput;
c_stream.total_out = 0;
}
}
while( err == Z_OK );
// Finish flushing it out
do
{
// Compress!
err = deflate( &c_stream, Z_FINISH );
// Flush output buffer?
if( c_stream.total_out > 0 )
{
// Suck up what's in there
m_checksum = adler32( m_checksum, (const Bytef *) m_bufferOutput, c_stream.total_out );
status = m_pstrm->ProcessWrite( m_bufferOutput, c_stream.total_out );
// Re-init the output buffer
c_stream.next_out = m_bufferOutput;
c_stream.avail_out = m_sizeOutput;
c_stream.total_out = 0;
}
}
while( err != Z_STREAM_END );
err = deflateEnd(&c_stream);
return status;
}
bool CPQDIF_SP_ZLIB::StreamDecode( void )
{
bool status = FALSE;
bool haveData;
long sizeActual = 0;
z_stream c_stream; /* decompression stream */
int err;
// Init
memset( &c_stream, 0, sizeof( c_stream ) );
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = inflateInit(&c_stream);
// Init output buffer
c_stream.next_out = m_bufferOutput;
c_stream.avail_out = m_sizeOutput;
c_stream.total_out = 0;
do
{
// Fill up the input buffer?
if( c_stream.avail_in == 0 )
{
haveData = m_pstrm->ProcessRead( m_buffer, m_maxBuffer, sizeActual );
if( !haveData )
{
// End of data
break;
}
c_stream.next_in = m_buffer;
c_stream.avail_in = sizeActual;
}
// Compress!
err = inflate( &c_stream, Z_NO_FLUSH );
// Flush output buffer?
if( c_stream.total_out > 0 )
{
// Suck up what's in there
status = m_pstrm->ProcessWrite( m_bufferOutput, c_stream.total_out );
// Re-init the output buffer
c_stream.next_out = m_bufferOutput;
c_stream.avail_out = m_sizeOutput;
c_stream.total_out = 0;
}
if (err == Z_STREAM_END)
break;
}
while( err == Z_OK );
err = inflateEnd(&c_stream);
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -