28#include <opendht/crypto.h>
35#include <minizip/mz.h>
36#include <minizip/mz_strm.h>
37#include <minizip/mz_strm_os.h>
38#include <minizip/mz_zip.h>
39#include <minizip/mz_zip_rw.h>
42#include <archive_entry.h>
50using namespace std::literals;
67 throw std::runtime_error(fmt::format(
"Exception during zlib compression: ({})",
ret));
92 std::vector<uint8_t>
out;
100 throw std::runtime_error(
"Exception during gzip decompression");
115 throw std::runtime_error(
"inflateInit failed while decompressing.");
118 zs.avail_in =
str.size();
121 std::vector<uint8_t>
out;
133 if (
out.size() <
zs.total_out) {
143 throw(std::runtime_error(fmt::format(
"Exception during zlib decompression: ({})",
ret)));
155 return gzopen(path.c_str(), mode);
160#if !defined(__APPLE__)
211#if defined(__APPLE__)
214 dhtnet::fileutils::check_dir(
dir.c_str());
220 while (status ==
MZ_OK) {
222 if (status !=
MZ_OK) {
223 dhtnet::fileutils::removeAll(
dir,
true);
226 std::string_view filename(info->filename, (
size_t) info->filename_size);
231 dhtnet::fileutils::check_dir(
directory.c_str());
246 dhtnet::fileutils::removeAll(
dir,
true);
253 dhtnet::fileutils::removeAll(
dir,
true);
283 throw std::runtime_error(
"Open Archive: " + archivePath +
"\t"
294 throw std::runtime_error(
"Error reading archive: "s
308 dhtnet::fileutils::removeAll(
dir);
309 throw std::runtime_error(
"Write file header: " +
fileEntry +
"\t"
323 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
331 dhtnet::fileutils::removeAll(
dir);
332 throw std::runtime_error(
"Write file data: " +
fileEntry +
"\t"
348#if defined(__APPLE__)
355 while (status ==
MZ_OK) {
359 std::string_view filename(info->filename, (
size_t) info->filename_size);
365 info->uncompressed_size);
386 throw std::runtime_error(
"Open Archive: " + archivePath +
"\t"
414 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
433std::vector<std::string>
438#if defined(__APPLE__)
446 while (status ==
MZ_OK) {
450 std::string filename(info->filename, (
size_t) info->filename_size);
462 throw std::runtime_error(
"Open Archive: " + path +
"\t"
#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)