Fixed some problems with the buffering

This commit is contained in:
Martin Gallwey
2000-11-16 21:50:51 +00:00
parent 05ac3fe285
commit f987a8b5e9
3 changed files with 69 additions and 57 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: Deflater.cxx,v $
*
* $Revision: 1.1 $
* $Revision: 1.2 $
*
* last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $
* last change: $Author: mtg $ $Date: 2000-11-16 22:50:51 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -81,7 +81,7 @@ Deflater::~Deflater(void)
if (pStream)
delete pStream;
}
void Deflater::init (sal_Int16 nLevel, sal_Int16 nStrategy, sal_Bool bNowrap)
void Deflater::init (sal_Int32 nLevel, sal_Int32 nStrategy, sal_Bool bNowrap)
{
pStream = new z_stream;
/* Memset it to 0...sets zalloc/zfree/opaque to NULL */
@@ -114,7 +114,7 @@ Deflater::Deflater()
init(DEFAULT_COMPRESSION, DEFAULT_STRATEGY, sal_False);
}
Deflater::Deflater(sal_Int16 nSetLevel)
Deflater::Deflater(sal_Int32 nSetLevel)
: nLevel(nSetLevel)
, nStrategy(DEFAULT_STRATEGY)
, bFinish(sal_False)
@@ -126,7 +126,7 @@ Deflater::Deflater(sal_Int16 nSetLevel)
init(nSetLevel, DEFAULT_STRATEGY, sal_False);
}
Deflater::Deflater(sal_Int16 nSetLevel, sal_Bool bNowrap)
Deflater::Deflater(sal_Int32 nSetLevel, sal_Bool bNowrap)
: nLevel(nSetLevel)
, nStrategy(DEFAULT_STRATEGY)
, bFinish(sal_False)
@@ -138,38 +138,58 @@ Deflater::Deflater(sal_Int16 nSetLevel, sal_Bool bNowrap)
init(nSetLevel, DEFAULT_STRATEGY, bNowrap);
}
sal_Int16 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int16 nNewOffset, sal_Int16 nNewLength)
sal_Int32 Deflater::doDeflateBytes (uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength)
{
sal_Int16 nResult;
sal_Int32 nResult;
if (bSetParams)
{
pStream->next_in = (unsigned char*) sInBuffer.getConstArray();
pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
pStream->avail_in = nLength;
pStream->avail_out = nNewLength;
nResult = z_deflateParams(pStream, nLevel, nStrategy);
bSetParams = sal_False;
switch (nResult)
{
case Z_OK:
bSetParams = sal_False;
nOffset += nLength - pStream->avail_in;
nLength = pStream->avail_in;
return nNewLength - pStream->avail_out;
case Z_BUF_ERROR:
bSetParams = sal_False;
DBG_ERROR( pStream->msg );
return 0;
default:
DBG_ERROR( pStream->msg );
return 0;
}
}
pStream->next_in = (unsigned char*) sInBuffer.getConstArray();
pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
pStream->avail_in = nLength;
pStream->avail_out = nNewLength;
nResult = z_deflate(pStream, Z_FINISH);
switch (nResult)
else
{
case Z_STREAM_END:
bFinished = sal_True;
case Z_OK:
nOffset += nLength - pStream->avail_in;
nLength = pStream->avail_in;
return nNewLength - pStream->avail_out;
case Z_BUF_ERROR:
bSetParams = sal_False;
DBG_ERROR( pStream->msg );
return 0;
default:
DBG_ERROR( pStream->msg );
return 0;
pStream->next_in = (unsigned char*) sInBuffer.getConstArray();
pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
pStream->avail_in = nLength;
pStream->avail_out = nNewLength;
nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH);
switch (nResult)
{
case Z_STREAM_END:
bFinished = sal_True;
case Z_OK:
nOffset += nLength - pStream->avail_in;
nLength = pStream->avail_in;
return nNewLength - pStream->avail_out;
case Z_BUF_ERROR:
bSetParams = sal_False;
DBG_ERROR( pStream->msg );
return 0;
default:
DBG_ERROR( pStream->msg );
return 0;
}
}
return 0;
}
void SAL_CALL Deflater::setInputSegment( const uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
@@ -201,7 +221,7 @@ void SAL_CALL Deflater::setDictionarySegment( const uno::Sequence< sal_Int8 >& r
{
// do error handling
}
sal_Int16 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray()+nOffset, nLength);
sal_Int32 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray()+nOffset, nLength);
}
void SAL_CALL Deflater::setDictionary( const uno::Sequence< sal_Int8 >& rBuffer )
throw(uno::RuntimeException)
@@ -212,7 +232,7 @@ void SAL_CALL Deflater::setDictionary( const uno::Sequence< sal_Int8 >& rBuffer
DBG_ERROR("No stream!");
}
sal_Int16 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray(), rBuffer.getLength());
sal_Int32 nResult = z_deflateSetDictionary(pStream, (const unsigned char*)rBuffer.getConstArray(), rBuffer.getLength());
}
void SAL_CALL Deflater::setStrategy( sal_Int32 nNewStrategy )
throw(uno::RuntimeException)
@@ -261,9 +281,7 @@ sal_Int32 SAL_CALL Deflater::doDeflateSegment( uno::Sequence< sal_Int8 >& rBuffe
throw(uno::RuntimeException)
{
if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())
{
// do error handling
}
DBG_ERROR("Invalid Offset or Length passed to doDeflateSegment");
return doDeflateBytes(rBuffer, nNewOffset, nNewLength);
}
sal_Int32 SAL_CALL Deflater::doDeflate( uno::Sequence< sal_Int8 >& rBuffer )

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: Inflater.cxx,v $
*
* $Revision: 1.1 $
* $Revision: 1.2 $
*
* last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $
* last change: $Author: mtg $ $Date: 2000-11-16 22:50:51 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,7 +71,7 @@ void Inflater::init (sal_Bool bNowrap)
pStream = new z_stream;
/* memset to 0 to set zalloc/opaque etc */
memset (pStream, 0, sizeof(*pStream));
sal_Int16 nRes;
sal_Int32 nRes;
nRes = inflateInit2(pStream, bNowrap ? -MAX_WBITS : MAX_WBITS);
switch (nRes)
{
@@ -235,9 +235,9 @@ void SAL_CALL Inflater::end( )
pStream = NULL;
}
sal_Int16 Inflater::doInflateBytes (com::sun::star::uno::Sequence < sal_Int8 > &rBuffer, sal_Int16 nNewOffset, sal_Int16 nNewLength)
sal_Int32 Inflater::doInflateBytes (com::sun::star::uno::Sequence < sal_Int8 > &rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength)
{
sal_Int16 nResult;
sal_Int32 nResult;
pStream->next_in = (unsigned char*) sInBuffer.getConstArray()+ nOffset;
pStream->avail_in = nLength;
pStream->next_out = (unsigned char*) rBuffer.getArray() + nNewOffset;
@@ -252,7 +252,7 @@ sal_Int16 Inflater::doInflateBytes (com::sun::star::uno::Sequence < sal_Int8 >
case Z_OK:
nOffset += nLength - pStream->avail_in;
nLength = pStream->avail_in;
return nLength - pStream->avail_out;
return nNewLength - pStream->avail_out;
case Z_NEED_DICT:
bNeedDict = sal_True;
nOffset += nLength - pStream->avail_in;

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ZipOutputStream.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $
* last change: $Author: mtg $ $Date: 2000-11-16 22:50:51 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -119,10 +119,10 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry )
case DEFLATED:
if (pNonConstEntry->nSize == -1 || pNonConstEntry->nCompressedSize == -1 ||
pNonConstEntry->nCrc == -1)
pNonConstEntry->nFlag |= 8;
pNonConstEntry->nFlag = 8;
else if (pNonConstEntry->nSize != -1 && pNonConstEntry->nCompressedSize != -1 &&
pNonConstEntry->nCrc != -1)
pNonConstEntry->nFlag &= 8;
pNonConstEntry->nFlag = 0;
pNonConstEntry->nVersion = 20;
break;
case STORED:
@@ -131,7 +131,7 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry )
else if (pNonConstEntry->nCompressedSize == -1)
pNonConstEntry->nCompressedSize = pNonConstEntry->nSize;
pNonConstEntry->nVersion = 10;
pNonConstEntry->nFlag &= 8;
pNonConstEntry->nFlag = 0;
break;
}
pNonConstEntry->nOffset = aChucker.getPosition();
@@ -161,17 +161,17 @@ void SAL_CALL ZipOutputStream::closeEntry( )
{
if (pEntry->nSize != aDeflater.getTotalIn())
{
// boom
DBG_ERROR("Invalid entry size");
}
if (pEntry->nCompressedSize != aDeflater.getTotalOut())
{
// boom
DBG_ERROR("Invalid entry compressed size");
//DBG_ERROR("Invalid entry compressed size");
// Different compression strategies make the merit of this
// test somewhat dubious
pEntry->nCompressedSize = aDeflater.getTotalOut();
}
if (pEntry->nCrc != aCRC.getValue())
{
// boom
DBG_ERROR("Invalid entry CRC-32");
}
}
@@ -185,12 +185,6 @@ void SAL_CALL ZipOutputStream::closeEntry( )
aDeflater.reset();
break;
case STORED:
{
sal_uInt32 na= pEntry->nCrc;
sal_uInt32 nb = aCRC.getValue();
int i=0;
}
if (static_cast < sal_uInt32 > (pEntry->nCrc) != static_cast <sal_uInt32> (aCRC.getValue()))
{
// boom
@@ -246,7 +240,7 @@ void SAL_CALL ZipOutputStream::finish( )
}
void ZipOutputStream::doDeflate()
{
sal_Int16 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
if (nLength > 0 )
{
aChucker.writeBytes(aBuffer);