Fixed some problems with the buffering
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: Deflater.cxx,v $
|
* $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
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -81,7 +81,7 @@ Deflater::~Deflater(void)
|
|||||||
if (pStream)
|
if (pStream)
|
||||||
delete 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;
|
pStream = new z_stream;
|
||||||
/* Memset it to 0...sets zalloc/zfree/opaque to NULL */
|
/* Memset it to 0...sets zalloc/zfree/opaque to NULL */
|
||||||
@@ -114,7 +114,7 @@ Deflater::Deflater()
|
|||||||
init(DEFAULT_COMPRESSION, DEFAULT_STRATEGY, sal_False);
|
init(DEFAULT_COMPRESSION, DEFAULT_STRATEGY, sal_False);
|
||||||
}
|
}
|
||||||
|
|
||||||
Deflater::Deflater(sal_Int16 nSetLevel)
|
Deflater::Deflater(sal_Int32 nSetLevel)
|
||||||
: nLevel(nSetLevel)
|
: nLevel(nSetLevel)
|
||||||
, nStrategy(DEFAULT_STRATEGY)
|
, nStrategy(DEFAULT_STRATEGY)
|
||||||
, bFinish(sal_False)
|
, bFinish(sal_False)
|
||||||
@@ -126,7 +126,7 @@ Deflater::Deflater(sal_Int16 nSetLevel)
|
|||||||
init(nSetLevel, DEFAULT_STRATEGY, sal_False);
|
init(nSetLevel, DEFAULT_STRATEGY, sal_False);
|
||||||
}
|
}
|
||||||
|
|
||||||
Deflater::Deflater(sal_Int16 nSetLevel, sal_Bool bNowrap)
|
Deflater::Deflater(sal_Int32 nSetLevel, sal_Bool bNowrap)
|
||||||
: nLevel(nSetLevel)
|
: nLevel(nSetLevel)
|
||||||
, nStrategy(DEFAULT_STRATEGY)
|
, nStrategy(DEFAULT_STRATEGY)
|
||||||
, bFinish(sal_False)
|
, bFinish(sal_False)
|
||||||
@@ -138,38 +138,58 @@ Deflater::Deflater(sal_Int16 nSetLevel, sal_Bool bNowrap)
|
|||||||
init(nSetLevel, DEFAULT_STRATEGY, 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)
|
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);
|
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();
|
else
|
||||||
pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
|
|
||||||
pStream->avail_in = nLength;
|
|
||||||
pStream->avail_out = nNewLength;
|
|
||||||
|
|
||||||
|
|
||||||
nResult = z_deflate(pStream, Z_FINISH);
|
|
||||||
switch (nResult)
|
|
||||||
{
|
{
|
||||||
case Z_STREAM_END:
|
pStream->next_in = (unsigned char*) sInBuffer.getConstArray();
|
||||||
bFinished = sal_True;
|
pStream->next_out = (unsigned char*) rBuffer.getArray()+nNewOffset;
|
||||||
case Z_OK:
|
pStream->avail_in = nLength;
|
||||||
nOffset += nLength - pStream->avail_in;
|
pStream->avail_out = nNewLength;
|
||||||
nLength = pStream->avail_in;
|
|
||||||
return nNewLength - pStream->avail_out;
|
nResult = z_deflate(pStream, bFinish ? Z_FINISH : Z_NO_FLUSH);
|
||||||
case Z_BUF_ERROR:
|
switch (nResult)
|
||||||
bSetParams = sal_False;
|
{
|
||||||
DBG_ERROR( pStream->msg );
|
case Z_STREAM_END:
|
||||||
return 0;
|
bFinished = sal_True;
|
||||||
default:
|
case Z_OK:
|
||||||
DBG_ERROR( pStream->msg );
|
nOffset += nLength - pStream->avail_in;
|
||||||
return 0;
|
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 )
|
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
|
// 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 )
|
void SAL_CALL Deflater::setDictionary( const uno::Sequence< sal_Int8 >& rBuffer )
|
||||||
throw(uno::RuntimeException)
|
throw(uno::RuntimeException)
|
||||||
@@ -212,7 +232,7 @@ void SAL_CALL Deflater::setDictionary( const uno::Sequence< sal_Int8 >& rBuffer
|
|||||||
DBG_ERROR("No stream!");
|
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 )
|
void SAL_CALL Deflater::setStrategy( sal_Int32 nNewStrategy )
|
||||||
throw(uno::RuntimeException)
|
throw(uno::RuntimeException)
|
||||||
@@ -261,9 +281,7 @@ sal_Int32 SAL_CALL Deflater::doDeflateSegment( uno::Sequence< sal_Int8 >& rBuffe
|
|||||||
throw(uno::RuntimeException)
|
throw(uno::RuntimeException)
|
||||||
{
|
{
|
||||||
if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())
|
if (nNewOffset < 0 || nNewLength < 0 || nNewOffset + nNewLength > rBuffer.getLength())
|
||||||
{
|
DBG_ERROR("Invalid Offset or Length passed to doDeflateSegment");
|
||||||
// do error handling
|
|
||||||
}
|
|
||||||
return doDeflateBytes(rBuffer, nNewOffset, nNewLength);
|
return doDeflateBytes(rBuffer, nNewOffset, nNewLength);
|
||||||
}
|
}
|
||||||
sal_Int32 SAL_CALL Deflater::doDeflate( uno::Sequence< sal_Int8 >& rBuffer )
|
sal_Int32 SAL_CALL Deflater::doDeflate( uno::Sequence< sal_Int8 >& rBuffer )
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: Inflater.cxx,v $
|
* $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
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -71,7 +71,7 @@ void Inflater::init (sal_Bool bNowrap)
|
|||||||
pStream = new z_stream;
|
pStream = new z_stream;
|
||||||
/* memset to 0 to set zalloc/opaque etc */
|
/* memset to 0 to set zalloc/opaque etc */
|
||||||
memset (pStream, 0, sizeof(*pStream));
|
memset (pStream, 0, sizeof(*pStream));
|
||||||
sal_Int16 nRes;
|
sal_Int32 nRes;
|
||||||
nRes = inflateInit2(pStream, bNowrap ? -MAX_WBITS : MAX_WBITS);
|
nRes = inflateInit2(pStream, bNowrap ? -MAX_WBITS : MAX_WBITS);
|
||||||
switch (nRes)
|
switch (nRes)
|
||||||
{
|
{
|
||||||
@@ -235,9 +235,9 @@ void SAL_CALL Inflater::end( )
|
|||||||
pStream = NULL;
|
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->next_in = (unsigned char*) sInBuffer.getConstArray()+ nOffset;
|
||||||
pStream->avail_in = nLength;
|
pStream->avail_in = nLength;
|
||||||
pStream->next_out = (unsigned char*) rBuffer.getArray() + nNewOffset;
|
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:
|
case Z_OK:
|
||||||
nOffset += nLength - pStream->avail_in;
|
nOffset += nLength - pStream->avail_in;
|
||||||
nLength = pStream->avail_in;
|
nLength = pStream->avail_in;
|
||||||
return nLength - pStream->avail_out;
|
return nNewLength - pStream->avail_out;
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
bNeedDict = sal_True;
|
bNeedDict = sal_True;
|
||||||
nOffset += nLength - pStream->avail_in;
|
nOffset += nLength - pStream->avail_in;
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: ZipOutputStream.cxx,v $
|
* $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
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -119,10 +119,10 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry )
|
|||||||
case DEFLATED:
|
case DEFLATED:
|
||||||
if (pNonConstEntry->nSize == -1 || pNonConstEntry->nCompressedSize == -1 ||
|
if (pNonConstEntry->nSize == -1 || pNonConstEntry->nCompressedSize == -1 ||
|
||||||
pNonConstEntry->nCrc == -1)
|
pNonConstEntry->nCrc == -1)
|
||||||
pNonConstEntry->nFlag |= 8;
|
pNonConstEntry->nFlag = 8;
|
||||||
else if (pNonConstEntry->nSize != -1 && pNonConstEntry->nCompressedSize != -1 &&
|
else if (pNonConstEntry->nSize != -1 && pNonConstEntry->nCompressedSize != -1 &&
|
||||||
pNonConstEntry->nCrc != -1)
|
pNonConstEntry->nCrc != -1)
|
||||||
pNonConstEntry->nFlag &= 8;
|
pNonConstEntry->nFlag = 0;
|
||||||
pNonConstEntry->nVersion = 20;
|
pNonConstEntry->nVersion = 20;
|
||||||
break;
|
break;
|
||||||
case STORED:
|
case STORED:
|
||||||
@@ -131,7 +131,7 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry )
|
|||||||
else if (pNonConstEntry->nCompressedSize == -1)
|
else if (pNonConstEntry->nCompressedSize == -1)
|
||||||
pNonConstEntry->nCompressedSize = pNonConstEntry->nSize;
|
pNonConstEntry->nCompressedSize = pNonConstEntry->nSize;
|
||||||
pNonConstEntry->nVersion = 10;
|
pNonConstEntry->nVersion = 10;
|
||||||
pNonConstEntry->nFlag &= 8;
|
pNonConstEntry->nFlag = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pNonConstEntry->nOffset = aChucker.getPosition();
|
pNonConstEntry->nOffset = aChucker.getPosition();
|
||||||
@@ -161,17 +161,17 @@ void SAL_CALL ZipOutputStream::closeEntry( )
|
|||||||
{
|
{
|
||||||
if (pEntry->nSize != aDeflater.getTotalIn())
|
if (pEntry->nSize != aDeflater.getTotalIn())
|
||||||
{
|
{
|
||||||
// boom
|
|
||||||
DBG_ERROR("Invalid entry size");
|
DBG_ERROR("Invalid entry size");
|
||||||
}
|
}
|
||||||
if (pEntry->nCompressedSize != aDeflater.getTotalOut())
|
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())
|
if (pEntry->nCrc != aCRC.getValue())
|
||||||
{
|
{
|
||||||
// boom
|
|
||||||
DBG_ERROR("Invalid entry CRC-32");
|
DBG_ERROR("Invalid entry CRC-32");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,12 +185,6 @@ void SAL_CALL ZipOutputStream::closeEntry( )
|
|||||||
aDeflater.reset();
|
aDeflater.reset();
|
||||||
break;
|
break;
|
||||||
case STORED:
|
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()))
|
if (static_cast < sal_uInt32 > (pEntry->nCrc) != static_cast <sal_uInt32> (aCRC.getValue()))
|
||||||
{
|
{
|
||||||
// boom
|
// boom
|
||||||
@@ -246,7 +240,7 @@ void SAL_CALL ZipOutputStream::finish( )
|
|||||||
}
|
}
|
||||||
void ZipOutputStream::doDeflate()
|
void ZipOutputStream::doDeflate()
|
||||||
{
|
{
|
||||||
sal_Int16 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
|
sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
|
||||||
if (nLength > 0 )
|
if (nLength > 0 )
|
||||||
{
|
{
|
||||||
aChucker.writeBytes(aBuffer);
|
aChucker.writeBytes(aBuffer);
|
||||||
|
Reference in New Issue
Block a user