diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-10-21 09:20:24 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-11-17 10:49:21 +0100 |
commit | 3e3b8483d7866e96bc75ddda283416c6829714af (patch) | |
tree | 28b0417cd7b7299c1ca69ce7f652bbbb0272d009 /package/source | |
parent | 3e7ab1ac1dc91544bdc58949ac62853b0ee33760 (diff) |
package: Use memory stream for compressing zip entries
Change-Id: Ibf81dc3cd8a9a9da3dfd6ee6e587a522c4d56a44
Diffstat (limited to 'package/source')
-rw-r--r-- | package/source/zipapi/ZipOutputEntry.cxx | 18 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 5 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 8 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageStream.cxx | 4 |
4 files changed, 20 insertions, 15 deletions
diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx index ca08abbec3cf..bcbb6ebe6d9b 100644 --- a/package/source/zipapi/ZipOutputEntry.cxx +++ b/package/source/zipapi/ZipOutputEntry.cxx @@ -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(); diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 29c19c42667a..d4f045668a8f 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -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) { diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 23a737e31264..a802fd5e372b 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -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(); } diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index edc1c7aa1818..590ff0e404d7 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -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(); } |