Compress game binary diffs using zstd
This commit is contained in:
parent
2546d92b92
commit
b2546a24e0
@ -70,7 +70,7 @@ namespace binary_loader
|
||||
|
||||
std::string result(reinterpret_cast<char*>(diff.data()), diff.size());
|
||||
result.append(reinterpret_cast<const char*>(&size), sizeof(size));
|
||||
result = utils::compression::zlib::compress(result);
|
||||
result = utils::compression::zstd::compress(result);
|
||||
|
||||
utils::io::write_file(file + ".diff", result);
|
||||
}
|
||||
@ -115,7 +115,7 @@ namespace binary_loader
|
||||
}
|
||||
|
||||
auto delta = load_delta(mode);
|
||||
delta = utils::compression::zlib::decompress(delta);
|
||||
delta = utils::compression::zstd::decompress(delta);
|
||||
return build_binary(base, delta);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -51,6 +51,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include <zlib.h>
|
||||
#include <zstd.h>
|
||||
#include <diff.h>
|
||||
#include <patch.h>
|
||||
#include <tomcrypt.h>
|
||||
|
@ -67,4 +67,26 @@ namespace utils::compression
|
||||
inflateEnd(&stream);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string zstd::compress(const std::string& data)
|
||||
{
|
||||
memory::allocator allocator;
|
||||
const auto bound = ZSTD_compressBound(data.size());
|
||||
|
||||
auto* buffer = allocator.allocate_array<char>(bound);
|
||||
const auto size = ZSTD_compress(buffer, bound, data.data(), data.size(), ZSTD_maxCLevel());
|
||||
|
||||
return std::string(buffer, size);
|
||||
}
|
||||
|
||||
std::string zstd::decompress(const std::string& data)
|
||||
{
|
||||
memory::allocator allocator;
|
||||
const auto bound = size_t(ZSTD_getFrameContentSize(data.data(), data.size()));
|
||||
|
||||
auto* buffer = allocator.allocate_array<char>(bound);
|
||||
const auto size = ZSTD_decompress(buffer, bound, data.data(), data.size());
|
||||
|
||||
return std::string(buffer, size);
|
||||
}
|
||||
}
|
||||
|
@ -10,4 +10,11 @@ namespace utils::compression
|
||||
static std::string compress(const std::string& data);
|
||||
static std::string decompress(const std::string& data);
|
||||
};
|
||||
|
||||
class zstd final
|
||||
{
|
||||
public:
|
||||
static std::string compress(const std::string& data);
|
||||
static std::string decompress(const std::string& data);
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user