From: Vsevolod Stakhov Date: Thu, 26 Aug 2021 15:08:28 +0000 (+0100) Subject: [Minor] Lua_compression: Add support of the compression level for gzip X-Git-Tag: 3.1~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c7bca7a471a4d91ba5b7489ff234f30f92821dac;p=rspamd.git [Minor] Lua_compression: Add support of the compression level for gzip --- diff --git a/src/lua/lua_compress.c b/src/lua/lua_compress.c index 599a796e0..f383d27c2 100644 --- a/src/lua/lua_compress.c +++ b/src/lua/lua_compress.c @@ -323,7 +323,7 @@ lua_compress_zlib_compress (lua_State *L) struct rspamd_lua_text *t = NULL, *res; gsize sz; z_stream strm; - gint rc; + gint rc, comp_level = Z_DEFAULT_COMPRESSION; guchar *p; gsize remain; @@ -333,9 +333,18 @@ lua_compress_zlib_compress (lua_State *L) return luaL_error (L, "invalid arguments"); } + if (lua_isnumber (L, 2)) { + comp_level = lua_tointeger (L, 2); + + if (comp_level > Z_BEST_COMPRESSION || comp_level < Z_BEST_SPEED) { + return luaL_error (L, "invalid arguments: compression level must be between %d and %d", + Z_BEST_SPEED, Z_BEST_COMPRESSION); + } + } + memset (&strm, 0, sizeof (strm)); - rc = deflateInit2 (&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, + rc = deflateInit2 (&strm, comp_level, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL - 1, Z_DEFAULT_STRATEGY); if (rc != Z_OK) { diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 006917ad7..1ac69365a 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -401,7 +401,7 @@ LUA_FUNCTION_DEF (util, gzip_decompress); LUA_FUNCTION_DEF (util, inflate); /*** - * @function util.gzip_compress(data) + * @function util.gzip_compress(data, [level=1]) * Compresses input using gzip compression * * @param {string/rspamd_text} data input data