summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-24 14:43:06 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-11-17 10:49:23 +0100
commita42aa52acbbff738a00299de172ca85cb001d840 (patch)
tree612a5ee6e5e1e0f6caea41518254ef1ddee02f1a /package
parentfbf714b45625c50bb1c736ef231b5dbbab0016a1 (diff)
package: Add possibility to disable deflating in a thread
Change-Id: I4d98b6f8b3315b731206700eb65f08463299dda3
Diffstat (limited to 'package')
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx43
1 files changed, 30 insertions, 13 deletions
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& )