summaryrefslogtreecommitdiff
path: root/core/io/compression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/compression.cpp')
-rw-r--r--core/io/compression.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index f806c4da6d..8c8f0b3655 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -52,23 +52,22 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
}
} break;
- case MODE_DEFLATE: {
+ case MODE_DEFLATE:
+ case MODE_GZIP: {
+
+ int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
strm.zalloc = zipio_alloc;
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
- int level = GLOBAL_GET("compression/zlib/compression_level");
- int err = deflateInit(&strm, level);
+ int level = p_mode == MODE_DEFLATE ? GLOBAL_GET("compression/zlib/compression_level") : GLOBAL_GET("compression/gzip/compression_level");
+ int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
if (err != Z_OK)
return -1;
strm.avail_in = p_src_size;
int aout = deflateBound(&strm, p_src_size);
- /*if (aout>p_src_size) {
- deflateEnd(&strm);
- return -1;
- }*/
strm.avail_out = aout;
strm.next_in = (Bytef *)p_src;
strm.next_out = p_dst;
@@ -100,13 +99,16 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
return ss;
} break;
- case MODE_DEFLATE: {
+ case MODE_DEFLATE:
+ case MODE_GZIP: {
+
+ int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
strm.zalloc = zipio_alloc;
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
- int err = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
+ int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
if (err != Z_OK)
return -1;
int aout = deflateBound(&strm, p_src_size);
@@ -138,7 +140,10 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
}
return ret_size;
} break;
- case MODE_DEFLATE: {
+ case MODE_DEFLATE:
+ case MODE_GZIP: {
+
+ int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
strm.zalloc = zipio_alloc;
@@ -146,7 +151,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
- int err = inflateInit(&strm);
+ int err = inflateInit2(&strm, window_bits);
ERR_FAIL_COND_V(err != Z_OK, -1);
strm.avail_in = p_src_size;