From a42aa52acbbff738a00299de172ca85cb001d840 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Fri, 24 Oct 2014 14:43:06 +0200 Subject: package: Add possibility to disable deflating in a thread Change-Id: I4d98b6f8b3315b731206700eb65f08463299dda3 --- package/source/zippackage/ZipPackageStream.cxx | 43 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'package') diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 9f29a6800ecc..d5e0d62641c6 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -439,6 +439,20 @@ bool ZipPackageStream::ParsePackageRawStream() return true; } +static void deflateZipEntry(ZipOutputEntry *pZipEntry, + const uno::Reference< io::XInputStream >& xInStream) +{ + sal_Int32 nLength = 0; + uno::Sequence< sal_Int8 > aSeq(n_ConstBufferSize); + do + { + nLength = xInStream->readBytes(aSeq, n_ConstBufferSize); + pZipEntry->write(aSeq, 0, nLength); + } + while (nLength == n_ConstBufferSize); + pZipEntry->closeEntry(); +} + class DeflateThread: public comphelper::ThreadTask { ZipOutputEntry *mpEntry; @@ -454,16 +468,7 @@ public: private: virtual void doWork() SAL_OVERRIDE { - sal_Int32 nLength = 0; - uno::Sequence< sal_Int8 > aSeq(n_ConstBufferSize); - do - { - nLength = mxInStream->readBytes(aSeq, n_ConstBufferSize); - mpEntry->write(aSeq, 0, nLength); - } - while (nLength == n_ConstBufferSize); - mpEntry->closeEntry(); - + deflateZipEntry(mpEntry, mxInStream); mxInStream.clear(); } }; @@ -784,9 +789,21 @@ bool ZipPackageStream::saveChild( else { bParallelDeflate = true; - // Start a new thread deflating this zip entry - ZipOutputEntry *pZipEntry = new ZipOutputEntry(m_xContext, *pTempEntry, this, bToBeEncrypted); - rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) ); + if (bParallelDeflate) + { + // Start a new thread deflating this zip entry + ZipOutputEntry *pZipEntry = new ZipOutputEntry(m_xContext, *pTempEntry, this, bToBeEncrypted); + rZipOut.addDeflatingThread( pZipEntry, new DeflateThread(pZipEntry, xStream) ); + } + else + { + rZipOut.writeLOC(pTempEntry, bToBeEncrypted); + ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted); + deflateZipEntry(&aZipEntry, xStream); + uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData(); + rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength()); + rZipOut.rawCloseEntry(bToBeEncrypted); + } } } catch ( ZipException& ) -- cgit