LibreOffice Module package (master) 1
ZipOutputEntry.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
20#define INCLUDED_PACKAGE_INC_ZIPOUTPUTENTRY_HXX
21
22#include <com/sun/star/io/XOutputStream.hpp>
23#include <com/sun/star/io/XTempFile.hpp>
24#include <com/sun/star/uno/Reference.hxx>
25#include <com/sun/star/uno/XComponentContext.hpp>
26#include <com/sun/star/xml/crypto/XCipherContext.hpp>
27#include <com/sun/star/xml/crypto/XDigestContext.hpp>
28
29#include <package/Deflater.hxx>
31#include <unotools/tempfile.hxx>
32#include "CRC32.hxx"
33#include <atomic>
34#include <exception>
35
36struct ZipEntry;
39
41{
42protected:
43 css::uno::Reference< css::uno::XComponentContext > m_xContext;
44 css::uno::Reference< css::io::XOutputStream > m_xOutStream;
45
46 css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext;
47 css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext;
48
51 sal_Int16 m_nDigested;
54
55public:
56 virtual ~ZipOutputEntryBase() = default;
57
58 virtual void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) = 0;
59
62 bool isEncrypt() const { return m_bEncryptCurrentEntry; }
63
64 void closeEntry();
65
66protected:
68 css::uno::Reference< css::io::XOutputStream > xOutStream,
69 css::uno::Reference< css::uno::XComponentContext > xContext,
70 ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt, bool checkStream);
71
72 // Inherited classes call this with deflated data buffer.
73 void processDeflated( const css::uno::Sequence< sal_Int8 >& deflateBuffer, sal_Int32 nLength );
74 // Inherited classes call this with the input buffer.
75 void processInput( const css::uno::Sequence< sal_Int8 >& rBuffer );
76
77 virtual void finishDeflater() = 0;
78 virtual sal_Int64 getDeflaterTotalIn() const = 0;
79 virtual sal_Int64 getDeflaterTotalOut() const = 0;
80 virtual void deflaterReset() = 0;
81 virtual bool isDeflaterFinished() const = 0;
82};
83
84// Normal non-threaded case.
86{
87 css::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
89
90public:
92 const css::uno::Reference< css::io::XOutputStream >& rxOutStream,
93 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
94 ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
95 void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) override;
96 void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
97
98protected:
100 const css::uno::Reference< css::io::XOutputStream >& rxOutStream,
101 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
102 ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt, bool checkStream);
103 virtual void finishDeflater() override;
104 virtual sal_Int64 getDeflaterTotalIn() const override;
105 virtual sal_Int64 getDeflaterTotalOut() const override;
106 virtual void deflaterReset() override;
107 virtual bool isDeflaterFinished() const override;
108 void doDeflate();
109};
110
111// Class that runs the compression in a background thread.
113{
114 class Task;
116 std::exception_ptr m_aParallelDeflateException;
117 std::atomic<bool> m_bFinished;
118
119public:
121 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
122 ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
123 std::unique_ptr<comphelper::ThreadTask> createTask(
124 const std::shared_ptr<comphelper::ThreadTaskTag>& pTag,
125 const css::uno::Reference< css::io::XInputStream >& xInStream );
126 /* This block of methods is for threaded zipping, where we compress to a temp stream, whose
127 data is retrieved via getData */
128 void createBufferFile();
129 void setParallelDeflateException(const std::exception_ptr& exception) { m_aParallelDeflateException = exception; }
130 css::uno::Reference< css::io::XInputStream > getData() const;
131 const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; }
132 void closeBufferFile();
133 void deleteBufferFile();
134 bool isFinished() const { return m_bFinished; }
135private:
136 void setFinished() { m_bFinished = true; }
137};
138
139// Class that synchronously runs the compression in multiple threads (using ThreadDeflater).
141{
142 sal_Int64 totalIn;
143 sal_Int64 totalOut;
145public:
147 const css::uno::Reference< css::io::XOutputStream >& rxOutStream,
148 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
149 ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
150 void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream) override;
151private:
152 virtual void finishDeflater() override;
153 virtual sal_Int64 getDeflaterTotalIn() const override;
154 virtual sal_Int64 getDeflaterTotalOut() const override;
155 virtual void deflaterReset() override;
156 virtual bool isDeflaterFinished() const override;
157};
158
159#endif
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: CRC32.hxx:29
css::uno::Reference< css::io::XOutputStream > m_xOutStream
virtual ~ZipOutputEntryBase()=default
virtual sal_Int64 getDeflaterTotalIn() const =0
void processInput(const css::uno::Sequence< sal_Int8 > &rBuffer)
ZipEntry * m_pCurrentEntry
css::uno::Reference< css::uno::XComponentContext > m_xContext
ZipPackageStream * m_pCurrentStream
ZipPackageStream * getZipPackageStream()
css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext
css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext
void processDeflated(const css::uno::Sequence< sal_Int8 > &deflateBuffer, sal_Int32 nLength)
ZipEntry * getZipEntry()
virtual void finishDeflater()=0
virtual bool isDeflaterFinished() const =0
virtual sal_Int64 getDeflaterTotalOut() const =0
virtual void deflaterReset()=0
virtual void writeStream(const css::uno::Reference< css::io::XInputStream > &xInStream)=0
ZipOutputEntryBase(css::uno::Reference< css::io::XOutputStream > xOutStream, css::uno::Reference< css::uno::XComponentContext > xContext, ZipEntry &rEntry, ZipPackageStream *pStream, bool bEncrypt, bool checkStream)
This class is used to deflate Zip entries.
bool isEncrypt() const
std::unique_ptr< comphelper::ThreadTask > createTask(const std::shared_ptr< comphelper::ThreadTaskTag > &pTag, const css::uno::Reference< css::io::XInputStream > &xInStream)
ZipOutputEntryInThread(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ZipEntry &rEntry, ZipPackageStream *pStream, bool bEncrypt)
const std::exception_ptr & getParallelDeflateException() const
rtl::Reference< utl::TempFileFastService > m_xTempFile
css::uno::Reference< css::io::XInputStream > getData() const
std::atomic< bool > m_bFinished
void setParallelDeflateException(const std::exception_ptr &exception)
std::exception_ptr m_aParallelDeflateException
virtual void finishDeflater() override
virtual void deflaterReset() override
ZipOutputEntryParallel(const css::uno::Reference< css::io::XOutputStream > &rxOutStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext, ZipEntry &rEntry, ZipPackageStream *pStream, bool bEncrypt)
virtual bool isDeflaterFinished() const override
void writeStream(const css::uno::Reference< css::io::XInputStream > &xInStream) override
virtual sal_Int64 getDeflaterTotalIn() const override
virtual sal_Int64 getDeflaterTotalOut() const override
ZipOutputEntry(const css::uno::Reference< css::io::XOutputStream > &rxOutStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext, ZipEntry &rEntry, ZipPackageStream *pStream, bool bEncrypt)
virtual sal_Int64 getDeflaterTotalIn() const override
virtual void finishDeflater() override
virtual bool isDeflaterFinished() const override
virtual void deflaterReset() override
ZipUtils::Deflater m_aDeflater
void writeStream(const css::uno::Reference< css::io::XInputStream > &xInStream) override
ZipOutputEntry(const css::uno::Reference< css::io::XOutputStream > &rxOutStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext, ZipEntry &rEntry, ZipPackageStream *pStream, bool bEncrypt, bool checkStream)
void write(const css::uno::Sequence< sal_Int8 > &rBuffer)
virtual sal_Int64 getDeflaterTotalOut() const override
css::uno::Sequence< sal_Int8 > m_aDeflateBuffer