22#include <opendht/crypto.h>
29#include <minizip/mz.h>
30#include <minizip/mz_strm.h>
31#include <minizip/mz_strm_os.h>
32#include <minizip/mz_zip.h>
33#include <minizip/mz_zip_rw.h>
36#include <archive_entry.h>
45using namespace std::literals;
59 throw std::runtime_error(fmt::format(
"Exception during zlib compression: ({})",
ret));
84 std::vector<uint8_t>
out;
92 throw std::runtime_error(
"Exception during gzip decompression");
107 throw std::runtime_error(
"inflateInit failed while decompressing.");
110 zs.avail_in =
str.size();
113 std::vector<uint8_t>
out;
125 if (
out.size() <
zs.total_out) {
135 throw(std::runtime_error(fmt::format(
"Exception during zlib decompression: ({})",
ret)));
147 return gzopen(path.c_str(), mode);
152#if !defined(__APPLE__)
203#if defined(__APPLE__)
206 dhtnet::fileutils::check_dir(
dir.c_str());
212 while (status ==
MZ_OK) {
214 if (status !=
MZ_OK) {
215 dhtnet::fileutils::removeAll(
dir,
true);
218 std::string_view
filename(info->filename, (
size_t) info->filename_size);
223 dhtnet::fileutils::check_dir(
directory.c_str());
233 dhtnet::fileutils::removeAll(
dir,
true);
240 dhtnet::fileutils::removeAll(
dir,
true);
293 dhtnet::fileutils::removeAll(
dir);
294 throw std::runtime_error(
"Write file header: " +
fileEntry +
"\t"
308 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
316 dhtnet::fileutils::removeAll(
dir);
317 throw std::runtime_error(
"Write file data: " +
fileEntry +
"\t"
333#if defined(__APPLE__)
340 while (status ==
MZ_OK) {
344 std::string_view
filename(info->filename, (
size_t) info->filename_size);
381 throw std::runtime_error(
397 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
416std::vector<std::string>
421#if defined(__APPLE__)
429 while (status ==
MZ_OK) {
433 std::string
filename(info->filename, (
size_t) info->filename_size);
#define DIR_SEPARATOR_STR
void compressGzip(const std::string &str, const std::string &path)
Compress string to a Gzip file.
std::vector< uint8_t > decompress(const std::vector< uint8_t > &str)
Decompress an STL string using zlib and return the original data.
std::vector< std::string > listFilesFromArchive(const std::string &path)
listFilesFromArchive list all files from an archive
void uncompressArchive(const std::string &archivePath, const std::string &dir, const FileMatchPair &f)
uncompressArchive Uncompresses an archive and puts the different files in dir folder according to a F...
std::function< std::pair< bool, std::string_view >(std::string_view)> FileMatchPair
gzFile openGzip(const std::string &path, const char *mode)
Open Gzip file (uses wide string version of gzopen on windows)
std::vector< uint8_t > readFileFromArchive(const std::string &archivePath, const std::string &fileRelativePathName)
readFileFromArchive read a file from an archive without uncompressing the whole archive
std::vector< uint8_t > decompressGzip(const std::string &path)
Decompress Gzip file to bytes.
std::vector< uint8_t > compress(const std::string &str)
Compress a STL string using zlib with given compression level and return the binary data.
void emitSignal(Args... args)