diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-12-14 00:11:53 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-12-14 00:21:20 +0100 |
commit | f92183833fa569006602ac7e93c906d2094e0d4d (patch) | |
tree | 9eade04a981394c2d3129b4667f5c20d8e46dee5 /package/source/zipapi | |
parent | 43eca2d9f8d87363b5f4bf8c5df92bf06be08c08 (diff) |
package: Better to use temporary files for huge memory zip streams
ZipPackageBuffer was holding the whole compressed data stream in one
uno::Sequence which seems to be a lot for big documents in some cases.
Change-Id: Ib10d00ac54df9674231f4bbf047fab7e9b0a7d45
Diffstat (limited to 'package/source/zipapi')
-rw-r--r-- | package/source/zipapi/ZipOutputEntry.cxx | 13 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 16 |
2 files changed, 23 insertions, 6 deletions
diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx index abffb1d6aede..8243bdcdf76a 100644 --- a/package/source/zipapi/ZipOutputEntry.cxx +++ b/package/source/zipapi/ZipOutputEntry.cxx @@ -19,6 +19,7 @@ #include <ZipOutputEntry.hxx> +#include <com/sun/star/io/TempFile.hpp> #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <comphelper/storagehelper.hxx> @@ -57,8 +58,8 @@ ZipOutputEntry::ZipOutputEntry( } else { - m_pBuffer = new ZipPackageBuffer(n_ConstBufferSize); - m_xOutStream = m_pBuffer; + m_xTempFile = io::TempFile::create(rxContext); + m_xOutStream = m_xTempFile->getOutputStream(); } assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries"); if (m_bEncryptCurrentEntry) @@ -72,10 +73,12 @@ ZipOutputEntry::~ZipOutputEntry( void ) { } -uno::Sequence< sal_Int8 > ZipOutputEntry::getData() +uno::Reference< io::XInputStream > ZipOutputEntry::getData() { - m_pBuffer->realloc(m_pBuffer->getPosition()); - return m_pBuffer->getSequence(); + m_xOutStream->closeOutput(); + uno::Reference< io::XSeekable > xTempSeek(m_xOutStream, UNO_QUERY_THROW); + xTempSeek->seek(0); + return m_xTempFile->getInputStream(); } void ZipOutputEntry::closeEntry() diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 058cb3d2224d..5c49b1bfc6b7 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -20,6 +20,7 @@ #include <ZipOutputStream.hxx> #include <com/sun/star/packages/zip/ZipConstants.hpp> +#include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <comphelper/storagehelper.hxx> #include <osl/diagnose.h> @@ -101,7 +102,20 @@ void ZipOutputStream::finish() for (size_t i = 0; i < m_aEntries.size(); i++) { writeLOC(m_aEntries[i]->getZipEntry(), m_aEntries[i]->isEncrypt()); - rawWrite(m_aEntries[i]->getData()); + + sal_Int32 nRead; + uno::Sequence< sal_Int8 > aSequence(n_ConstBufferSize); + uno::Reference< io::XInputStream > xInput = m_aEntries[i]->getData(); + do + { + nRead = xInput->readBytes(aSequence, n_ConstBufferSize); + if (nRead < n_ConstBufferSize) + aSequence.realloc(nRead); + + rawWrite(aSequence); + } + while (nRead == n_ConstBufferSize); + rawCloseEntry(m_aEntries[i]->isEncrypt()); m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry()); |