Kaydet (Commit) 3e3b8483 authored tarafından Matúš Kukan's avatar Matúš Kukan

package: Use memory stream for compressing zip entries

Change-Id: Ibf81dc3cd8a9a9da3dfd6ee6e587a522c4d56a44
üst 3e7ab1ac
......@@ -29,19 +29,19 @@
#include <CRC32.hxx>
struct ZipEntry;
class ZipOutputStream;
class ZipPackageBuffer;
class ZipPackageStream;
class ZipOutputEntry
{
::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
ZipUtils::Deflater m_aDeflater;
ZipUtils::Deflater m_aDeflater;
css::uno::Reference< ZipPackageBuffer > m_pBuffer;
::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext;
::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext;
CRC32 m_aCRC;
ZipOutputStream* m_pZipOutputStream;
ZipEntry *m_pCurrentEntry;
sal_Int16 m_nDigested;
bool m_bEncryptCurrentEntry;
......@@ -50,10 +50,12 @@ class ZipOutputEntry
public:
ZipOutputEntry(
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
ZipOutputStream *pZipOutputStream, ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false);
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt = false);
~ZipOutputEntry();
css::uno::Sequence< sal_Int8 > getData();
// XZipOutputEntry interfaces
void SAL_CALL closeEntry( )
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
......
......@@ -53,7 +53,6 @@ public:
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
void finish()
throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
ByteChucker& getChucker();
static sal_uInt32 getCurrentDosTime();
......
......@@ -24,11 +24,10 @@
#include <osl/time.h>
#include <ByteChucker.hxx>
#include <PackageConstants.hxx>
#include <ZipEntry.hxx>
#include <ZipFile.hxx>
#include <ZipOutputStream.hxx>
#include <ZipPackageBuffer.hxx>
#include <ZipPackageStream.hxx>
using namespace com::sun::star;
......@@ -39,13 +38,12 @@ using namespace com::sun::star::packages::zip::ZipConstants;
/** This class is used to deflate Zip entries
*/
ZipOutputEntry::ZipOutputEntry( const uno::Reference< uno::XComponentContext >& rxContext,
ZipOutputStream* pOutputStream,
ZipEntry& rEntry,
ZipPackageStream* pStream,
bool bEncrypt)
: m_aDeflateBuffer(n_ConstBufferSize)
, m_aDeflater(DEFAULT_COMPRESSION, true)
, m_pZipOutputStream(pOutputStream)
, m_pBuffer(new ZipPackageBuffer(n_ConstBufferSize))
, m_pCurrentEntry(&rEntry)
, m_nDigested(0)
, m_bEncryptCurrentEntry(bEncrypt)
......@@ -64,6 +62,12 @@ ZipOutputEntry::~ZipOutputEntry( void )
{
}
uno::Sequence< sal_Int8 > ZipOutputEntry::getData()
{
m_pBuffer->realloc(m_pBuffer->getPosition());
return m_pBuffer->getSequence();
}
void SAL_CALL ZipOutputEntry::closeEntry()
throw(IOException, RuntimeException)
{
......@@ -151,7 +155,7 @@ void ZipOutputEntry::doDeflate()
// FIXME64: uno::Sequence not 64bit safe.
uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer );
m_pZipOutputStream->getChucker().WriteBytes( aEncryptionBuffer );
m_pBuffer->writeBytes( aEncryptionBuffer );
// the sizes as well as checksum for encrypted streams is calculated here
m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
......@@ -160,7 +164,7 @@ void ZipOutputEntry::doDeflate()
}
else
{
m_pZipOutputStream->getChucker().WriteBytes ( aTmpBuffer );
m_pBuffer->writeBytes ( aTmpBuffer );
}
}
......@@ -170,7 +174,7 @@ void ZipOutputEntry::doDeflate()
uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose();
if ( aEncryptionBuffer.getLength() )
{
m_pZipOutputStream->getChucker().WriteBytes( aEncryptionBuffer );
m_pBuffer->writeBytes( aEncryptionBuffer );
// the sizes as well as checksum for encrypted streams is calculated hier
m_pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength();
......
......@@ -108,11 +108,6 @@ void ZipOutputStream::finish( )
m_xStream->flush();
}
ByteChucker& ZipOutputStream::getChucker()
{
return m_aChucker;
}
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
throw(IOException, RuntimeException)
{
......
......@@ -1040,9 +1040,11 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Seq
// the manifest.xml is never encrypted - so pass an empty reference
aZipOut.putNextEntry(*pEntry);
ZipOutputEntry aZipEntry(m_xContext, &aZipOut, *pEntry, NULL);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
aZipOut.rawCloseEntry();
}
......@@ -1092,9 +1094,11 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno:
// there is no encryption in this format currently
aZipOut.putNextEntry(*pEntry);
ZipOutputEntry aZipEntry(m_xContext, &aZipOut, *pEntry, NULL);
ZipOutputEntry aZipEntry(m_xContext, *pEntry, NULL);
aZipEntry.write(pBuffer->getSequence(), 0, nBufferLength);
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
aZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
aZipOut.rawCloseEntry();
}
......
......@@ -748,7 +748,7 @@ bool ZipPackageStream::saveChild(
}
else
{
ZipOutputEntry aZipEntry(m_xContext, &rZipOut, *pTempEntry, this, bToBeEncrypted);
ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted);
do
{
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
......@@ -756,6 +756,8 @@ bool ZipPackageStream::saveChild(
}
while ( nLength == n_ConstBufferSize );
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
}
rZipOut.rawCloseEntry();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment