summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-21 09:20:24 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-11-05 22:54:17 +0100
commit4847e143f8ffd8e3fbd41b7cc0fcf423f2b7561d (patch)
tree05c336f34570c34c4c8e5b8d8fd72c1b4dc3fa3a /package
parentd10d70d8181753426f9c816cdd2ffca246b2c48c (diff)
package: Use memory stream for compressing zip entries
Change-Id: Ibf81dc3cd8a9a9da3dfd6ee6e587a522c4d56a44
Diffstat (limited to 'package')
-rw-r--r--package/inc/ZipOutputEntry.hxx10
-rw-r--r--package/inc/ZipOutputStream.hxx1
-rw-r--r--package/source/zipapi/ZipOutputEntry.cxx18
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx5
-rw-r--r--package/source/zippackage/ZipPackage.cxx8
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx4
6 files changed, 26 insertions, 20 deletions
diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx
index 73bd8a481afd..e04cebf7d23b 100644
--- a/package/inc/ZipOutputEntry.hxx
+++ b/package/inc/ZipOutputEntry.hxx
@@ -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);
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index 6775bd02c3be..0c8dafe6fee2 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -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();
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 d587b3a28dd1..3eb1c1e5eae7 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();
}