summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2017-07-13 14:41:10 -0300
committerGeorge Marques <george@gmarqu.es>2017-07-13 14:41:10 -0300
commit0f765c86e5b7fc771f5559b9e46999bd8e6239aa (patch)
tree63a7c4d2e2f20892f2fb7d37b491ec95b2a74201 /core/io
parentfca9c75f2b002f3bdcec086499e2ea07b86cf4a1 (diff)
Add GZIP compression support
- Fix a wrong call in PoolByteArray::compress
Diffstat (limited to 'core/io')
-rw-r--r--core/io/compression.cpp27
-rw-r--r--core/io/compression.h3
2 files changed, 18 insertions, 12 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;
diff --git a/core/io/compression.h b/core/io/compression.h
index 742f0f4d68..bc39fc4185 100644
--- a/core/io/compression.h
+++ b/core/io/compression.h
@@ -37,7 +37,8 @@ public:
enum Mode {
MODE_FASTLZ,
MODE_DEFLATE,
- MODE_ZSTD
+ MODE_ZSTD,
+ MODE_GZIP
};
static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD);