32 #ifndef WRAPPER_ZIPARCHIVE_HPP_ 33 #define WRAPPER_ZIPARCHIVE_HPP_ 77 [[nodiscard]]
struct zip *
get() noexcept;
78 [[nodiscard]]
const struct zip *
getc()
const noexcept;
79 [[nodiscard]]
bool valid()
const noexcept;
80 [[nodiscard]] std::string
getError();
89 const std::string& fileName,
90 const std::string& content,
98 void close() noexcept;
99 void close(std::string& dumpTo);
123 struct zip * ptr{
nullptr};
129 static void copyError(
const zip_error_t * from, zip_error_t& to);
143 if(!(this->source.
valid())) {
144 this->error = this->source.
getError();
150 this->ptr = zip_open_from_source(this->source.
get(), ZIP_TRUNCATE, &(this->error));
152 if(this->ptr !=
nullptr) {
154 zip_source_keep(this->source.
get());
195 return this->ptr !=
nullptr;
206 return zip_error_strerror(&(this->error));
230 if(this->ptr ==
nullptr) {
235 zip_add_dir(this->ptr, name.c_str())
240 ZipArchive::copyError(
241 zip_get_error(this->ptr),
271 const std::string& name,
272 const std::string& content,
275 if(this->ptr ==
nullptr) {
279 ZipSource fileSource(content.data(), content.size());
282 zip_source_keep(fileSource.get());
289 ZIP_FL_ENC_UTF_8 | (overwrite ? ZIP_FL_OVERWRITE : 0)
295 zip_source_free(fileSource.get());
297 ZipArchive::copyError(zip_get_error(this->ptr), this->error);
320 if(this->ptr !=
nullptr) {
321 zip_close(this->ptr);
326 zip_error_fini(&(this->error));
341 if(this->ptr ==
nullptr) {
347 if(this->source.
valid()) {
348 zip_source_open(this->source.
get());
350 zip_source_seek(this->source.
get(), 0, SEEK_END);
352 const zip_int64_t size{
353 zip_source_tell(this->source.
get())
356 zip_source_seek(this->source.
get(), 0, SEEK_SET);
362 static_cast<void*
>(dumpTo.data()),
413 this->ptr = other.ptr;
426 inline void ZipArchive::copyError(
const zip_error_t * from, zip_error_t& to) {
430 to.sys_err = from->sys_err;
431 to.zip_err = from->zip_err;
ZipArchive & operator=(ZipArchive &)=delete
Deleted copy assignment operator.
struct zip * get() noexcept
Gets a pointer to the underlying archive.
Definition: ZipArchive.hpp:172
bool valid() const noexcept
Checks whether the underlying archive is valid.
Definition: ZipArchive.hpp:194
virtual ~ZipArchive()
Destructor clearing the archive if necessary.
Definition: ZipArchive.hpp:159
bool addFile(const std::string &fileName, const std::string &content, bool overwrite)
Adds a file to the archive.
Definition: ZipArchive.hpp:270
ZipArchive()
Constructor creating an archive from an empty source.
Definition: ZipArchive.hpp:141
RAII wrapper for ZIP archives used by libzip.
Definition: ZipArchive.hpp:65
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
std::string getError()
Get the last occurred error as string.
Definition: ZipArchive.hpp:205
void close() noexcept
Closes the underlying archive if necessary.
Definition: ZipArchive.hpp:319
bool addEmptyDirectory(const std::string &name)
Adds an empty directory to the archive.
Definition: ZipArchive.hpp:229
bool valid() const noexcept
Checks whether the underlying source is valid.
Definition: ZipSource.hpp:165
const struct zip * getc() const noexcept
Gets a const pointer to the underlying archive.
Definition: ZipArchive.hpp:182
zip_error_t getError() const
Get the last occurred error.
Definition: ZipSource.hpp:176
RAII wrapper for sources used by libzip.
Definition: ZipSource.hpp:61
zip_source_t * get() noexcept
Gets a pointer to the underlying source.
Definition: ZipSource.hpp:143