diff options
author | Ferenc Arn <tagcup@yahoo.com> | 2017-06-08 20:43:56 -0500 |
---|---|---|
committer | Ferenc Arn <tagcup@yahoo.com> | 2017-06-08 23:48:14 -0500 |
commit | f177c1534757973063f244450df063def879d7db (patch) | |
tree | f92cf1c822d71acfe5e56ea42b80018abe0e0117 /core/io/compression.cpp | |
parent | 01ed55987c4c044191e50ecc94c277b97962ffc7 (diff) |
Add zstd compression support.
zstd has much better compression speed and ratio, and better decompression speed than currently available methods.
Also set zstd as the default compression method for Compression as well as FileAccessCompressed functions.
Diffstat (limited to 'core/io/compression.cpp')
-rw-r--r-- | core/io/compression.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 662411a62e..9c3e0e8eca 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -33,9 +33,12 @@ #include "zip_io.h" #include "thirdparty/misc/fastlz.h" +#include "thirdparty/zstd/zstd.h" #include <zlib.h> +#define ZSTD_DEFAULT_COMPRESSION 3 + int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) { switch (p_mode) { @@ -76,6 +79,11 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, return aout; } break; + case MODE_ZSTD: { + + int max_dst_size = get_max_compressed_buffer_size(p_src_size, MODE_ZSTD); + return ZSTD_compress(p_dst, max_dst_size, p_src, p_src_size, ZSTD_DEFAULT_COMPRESSION); + } break; } ERR_FAIL_V(-1); @@ -105,6 +113,10 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { deflateEnd(&strm); return aout; } break; + case MODE_ZSTD: { + + return ZSTD_compressBound(p_src_size); + } break; } ERR_FAIL_V(-1); @@ -148,6 +160,10 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p ERR_FAIL_COND_V(err != Z_STREAM_END, -1); return total; } break; + case MODE_ZSTD: { + + return ZSTD_decompress(p_dst, p_dst_max_size, p_src, p_src_size); + } break; } ERR_FAIL_V(-1); |