Replace ZCodec::mbInit with sane enum
...and document how the member functions are supposed to be called from client code. Change-Id: Ia4847945e4a361c43a0ed001e3e78e901c9abcad
This commit is contained in:
parent
d4af55670f
commit
1c92fbf4fd
@ -27,10 +27,16 @@
|
||||
|
||||
class SvStream;
|
||||
|
||||
// The overall client call protocol is one of:
|
||||
// * BeginCompression, Compress, EndCompression
|
||||
// * BeginCompression, Decompress, EndCompression
|
||||
// * BeginCompression, Write*, EndCompression
|
||||
// * BeginCompression, Read*, EndCompression
|
||||
// * BeginCompression, ReadAsynchron*, EndCompression
|
||||
class TOOLS_DLLPUBLIC ZCodec
|
||||
{
|
||||
private:
|
||||
sal_uIntPtr mbInit;
|
||||
enum State { STATE_INIT, STATE_DECOMPRESS, STATE_COMPRESS };
|
||||
State meState;
|
||||
bool mbStatus;
|
||||
bool mbFinish;
|
||||
SvStream* mpIStm;
|
||||
|
@ -38,7 +38,7 @@
|
||||
static const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */
|
||||
|
||||
ZCodec::ZCodec( sal_uIntPtr nInBufSize, sal_uIntPtr nOutBufSize )
|
||||
: mbInit(0)
|
||||
: meState(STATE_INIT)
|
||||
, mbStatus(false)
|
||||
, mbFinish(false)
|
||||
, mpIStm(NULL)
|
||||
@ -63,7 +63,7 @@ ZCodec::~ZCodec()
|
||||
|
||||
void ZCodec::BeginCompression( int nCompressLevel, bool updateCrc, bool gzLib )
|
||||
{
|
||||
mbInit = 0;
|
||||
assert(meState == STATE_INIT);
|
||||
mbStatus = true;
|
||||
mbFinish = false;
|
||||
mpIStm = mpOStm = NULL;
|
||||
@ -83,9 +83,9 @@ long ZCodec::EndCompression()
|
||||
{
|
||||
long retvalue = 0;
|
||||
|
||||
if ( mbInit != 0 )
|
||||
if (meState != STATE_INIT)
|
||||
{
|
||||
if ( mbInit & 2 ) // 1->decompress, 3->compress
|
||||
if (meState == STATE_COMPRESS)
|
||||
{
|
||||
do
|
||||
{
|
||||
@ -105,6 +105,7 @@ long ZCodec::EndCompression()
|
||||
}
|
||||
delete[] mpOutBuf;
|
||||
delete[] mpInBuf;
|
||||
meState = STATE_INIT;
|
||||
}
|
||||
return ( mbStatus ) ? retvalue : -1;
|
||||
}
|
||||
@ -113,13 +114,11 @@ long ZCodec::Compress( SvStream& rIStm, SvStream& rOStm )
|
||||
{
|
||||
long nOldTotal_In = PZSTREAM->total_in;
|
||||
|
||||
if ( mbInit == 0 )
|
||||
{
|
||||
assert(meState == STATE_INIT);
|
||||
mpIStm = &rIStm;
|
||||
mpOStm = &rOStm;
|
||||
ImplInitBuf( false );
|
||||
mpInBuf = new sal_uInt8[ mnInBufSize ];
|
||||
}
|
||||
while (( PZSTREAM->avail_in = mpIStm->Read( PZSTREAM->next_in = mpInBuf, mnInBufSize )) != 0 )
|
||||
{
|
||||
if ( PZSTREAM->avail_out == 0 )
|
||||
@ -139,16 +138,11 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm )
|
||||
sal_uIntPtr nInToRead;
|
||||
long nOldTotal_Out = PZSTREAM->total_out;
|
||||
|
||||
if ( mbFinish )
|
||||
return PZSTREAM->total_out - nOldTotal_Out;
|
||||
|
||||
if ( mbInit == 0 )
|
||||
{
|
||||
assert(meState == STATE_INIT);
|
||||
mpIStm = &rIStm;
|
||||
mpOStm = &rOStm;
|
||||
ImplInitBuf( true );
|
||||
PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
|
||||
}
|
||||
do
|
||||
{
|
||||
if ( PZSTREAM->avail_out == 0 ) ImplWriteBack();
|
||||
@ -173,14 +167,12 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm )
|
||||
while ( ( err != Z_STREAM_END) && ( PZSTREAM->avail_in || mnInToRead ) );
|
||||
ImplWriteBack();
|
||||
|
||||
if ( err == Z_STREAM_END )
|
||||
mbFinish = true;
|
||||
return ( mbStatus ) ? (long)(PZSTREAM->total_out - nOldTotal_Out) : -1;
|
||||
}
|
||||
|
||||
long ZCodec::Write( SvStream& rOStm, const sal_uInt8* pData, sal_uIntPtr nSize )
|
||||
{
|
||||
if ( mbInit == 0 )
|
||||
if (meState == STATE_INIT)
|
||||
{
|
||||
mpOStm = &rOStm;
|
||||
ImplInitBuf( false );
|
||||
@ -212,7 +204,7 @@ long ZCodec::Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize )
|
||||
return 0; // PZSTREAM->total_out;
|
||||
|
||||
mpIStm = &rIStm;
|
||||
if ( mbInit == 0 )
|
||||
if (meState == STATE_INIT)
|
||||
{
|
||||
ImplInitBuf( true );
|
||||
}
|
||||
@ -256,7 +248,7 @@ long ZCodec::ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize
|
||||
if ( mbFinish )
|
||||
return 0; // PZSTREAM->total_out;
|
||||
|
||||
if ( mbInit == 0 )
|
||||
if (meState == STATE_INIT)
|
||||
{
|
||||
mpIStm = &rIStm;
|
||||
ImplInitBuf( true );
|
||||
@ -308,7 +300,7 @@ void ZCodec::ImplWriteBack()
|
||||
|
||||
if ( nAvail )
|
||||
{
|
||||
if ( mbInit & 2 && mbUpdateCrc )
|
||||
if (meState == STATE_COMPRESS && mbUpdateCrc)
|
||||
UpdateCRC( mpOutBuf, nAvail );
|
||||
mpOStm->Write( PZSTREAM->next_out = mpOutBuf, nAvail );
|
||||
PZSTREAM->avail_out = mnOutBufSize;
|
||||
@ -337,11 +329,10 @@ sal_uIntPtr ZCodec::GetCRC()
|
||||
|
||||
void ZCodec::ImplInitBuf ( bool nIOFlag )
|
||||
{
|
||||
if ( mbInit == 0 )
|
||||
{
|
||||
assert(meState == STATE_INIT);
|
||||
if ( nIOFlag )
|
||||
{
|
||||
mbInit = 1;
|
||||
meState = STATE_DECOMPRESS;
|
||||
if ( mbStatus && mbGzLib )
|
||||
{
|
||||
sal_uInt8 n1, n2, j, nMethod, nFlags;
|
||||
@ -397,7 +388,7 @@ void ZCodec::ImplInitBuf ( bool nIOFlag )
|
||||
}
|
||||
else
|
||||
{
|
||||
mbInit = 3;
|
||||
meState = STATE_COMPRESS;
|
||||
|
||||
mbStatus = ( deflateInit2_( PZSTREAM, mnCompressLevel, Z_DEFLATED,
|
||||
MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
@ -405,7 +396,6 @@ void ZCodec::ImplInitBuf ( bool nIOFlag )
|
||||
|
||||
PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZCodec::UpdateCRC ( sal_uInt8* pSource, long nDatSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user