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 std::ostringstream
oss;
68 oss <<
"Exception during zlib compression: (" <<
ret <<
") ";
69 throw std::runtime_error(
oss.str());
94 std::vector<uint8_t>
out;
102 throw std::runtime_error(
"Exception during gzip decompression");
117 throw std::runtime_error(
"inflateInit failed while decompressing.");
120 zs.avail_in =
str.size();
123 std::vector<uint8_t>
out;
135 if (
out.size() <
zs.total_out) {
145 std::ostringstream
oss;
146 oss <<
"Exception during zlib decompression: (" <<
ret <<
") " <<
zs.msg;
147 throw(std::runtime_error(
oss.str()));
159 return gzopen(path.c_str(), mode);
164#if !defined(__APPLE__)
215#if defined(__APPLE__)
218 dhtnet::fileutils::check_dir(
dir.c_str());
224 while (status ==
MZ_OK) {
226 if (status !=
MZ_OK) {
227 dhtnet::fileutils::removeAll(
dir,
true);
230 std::string_view filename(info->filename, (
size_t) info->filename_size);
235 dhtnet::fileutils::check_dir(
directory.c_str());
250 dhtnet::fileutils::removeAll(
dir,
true);
257 dhtnet::fileutils::removeAll(
dir,
true);
287 throw std::runtime_error(
"Open Archive: " + archivePath +
"\t"
298 throw std::runtime_error(
"Error reading archive: "s
312 dhtnet::fileutils::removeAll(
dir);
313 throw std::runtime_error(
"Write file header: " +
fileEntry +
"\t"
327 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
335 dhtnet::fileutils::removeAll(
dir);
336 throw std::runtime_error(
"Write file data: " +
fileEntry +
"\t"
352#if defined(__APPLE__)
359 while (status ==
MZ_OK) {
363 std::string_view filename(info->filename, (
size_t) info->filename_size);
369 info->uncompressed_size);
390 throw std::runtime_error(
"Open Archive: " + archivePath +
"\t"
418 throw std::runtime_error(
"Read file data: " +
fileEntry +
"\t"
437std::vector<std::string>
442#if defined(__APPLE__)
450 while (status ==
MZ_OK) {
454 std::string filename(info->filename, (
size_t) info->filename_size);
466 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)