OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLZipArchive.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLZIPARCHIVE_HPP
12#define OPENXLSX_XLZIPARCHIVE_HPP
13
14#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif // _MSC_VER
19
20// ===== OpenXLSX Includes ===== //
21#include "OpenXLSX-Exports.hpp"
22
23#include <cstddef>
24#include <cstdint>
25#include <memory>
26#include <string>
27
28namespace OpenXLSX
29{
33 class OPENXLSX_EXPORT XLZipArchive
34 {
35 public:
40
45 XLZipArchive(const XLZipArchive& other) = default;
46
51 XLZipArchive(XLZipArchive&& other) noexcept = default;
52
57
63 XLZipArchive& operator=(const XLZipArchive& other) = default;
64
70 XLZipArchive& operator=(XLZipArchive&& other) noexcept = default;
71
76 explicit operator bool() const;
77
78 [[nodiscard]] bool isValid() const;
79
84 [[nodiscard]] bool isOpen() const;
85
90 void open(std::string_view fileName);
91
95 void close();
96
101 void save(std::string_view path = "");
102
108 void addEntry(std::string_view name, std::string data);
109
116 void addEntryAllocated(std::string_view name, void* data, size_t size);
117
123 void addEntryFromFile(std::string_view name, std::string_view filePath);
124
129 void deleteEntry(std::string_view entryName);
130
136 [[nodiscard]] std::string getEntry(std::string_view name) const;
137
142 void setMaxEntryUncompressedSize(size_t maxBytes) noexcept { m_maxEntryUncompressedSize = maxBytes; }
143 size_t maxEntryUncompressedSize() const noexcept { return m_maxEntryUncompressedSize; }
144
150 void* openEntryStream(std::string_view name) const;
151
159 int64_t readEntryStream(void* stream, char* buffer, uint64_t size) const;
160
165 void closeEntryStream(void* stream) const;
166
172 [[nodiscard]] bool hasEntry(std::string_view entryName) const;
173
178 [[nodiscard]] std::vector<std::string> entryNames() const;
179
184 void setCompressionLevel(int level);
185
189 int compressionLevel() const;
190
191 private:
192 struct LibZipApp;
193 std::shared_ptr<LibZipApp> m_archive;
194 int m_compressionLevel{1};
195 size_t m_maxEntryUncompressedSize{0};
196 };
197} // namespace OpenXLSX
198
199#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
200# pragma warning(pop)
201#endif // _MSC_VER
202
203#endif // OPENXLSX_XLZIPARCHIVE_HPP
void setMaxEntryUncompressedSize(size_t maxBytes) noexcept
Cap uncompressed size accepted by getEntry (0 = unlimited).
Definition XLZipArchive.hpp:142
void addEntryAllocated(std::string_view name, void *data, size_t size)
Directly adds an allocated buffer to the ZIP archive, transferring ownership to libzip.
Definition XLZipArchive.cpp:242
bool isValid() const
Definition XLZipArchive.cpp:77
void addEntry(std::string_view name, std::string data)
Definition XLZipArchive.cpp:201
size_t maxEntryUncompressedSize() const noexcept
Definition XLZipArchive.hpp:143
XLZipArchive(XLZipArchive &&other) noexcept=default
void deleteEntry(std::string_view entryName)
Definition XLZipArchive.cpp:279
std::string getEntry(std::string_view name) const
Definition XLZipArchive.cpp:292
void addEntryFromFile(std::string_view name, std::string_view filePath)
Add a file to the ZIP archive directly from the file system (useful for streaming large files).
Definition XLZipArchive.cpp:377
void open(std::string_view fileName)
Definition XLZipArchive.cpp:91
bool isOpen() const
Definition XLZipArchive.cpp:79
void save(std::string_view path="")
Definition XLZipArchive.cpp:165
XLZipArchive()
Definition XLZipArchive.cpp:71
void close()
Definition XLZipArchive.cpp:132
XLZipArchive(const XLZipArchive &other)=default
XLZipArchive & operator=(const XLZipArchive &other)=default
XLZipArchive & operator=(XLZipArchive &&other) noexcept=default
Definition IXLCellProvider.hpp:24