aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-29 14:20:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-29 14:20:31 +0100
commit05675bda7d2c8344f58679d7f66a904d30233c5d (patch)
treeb4735b2fd7d729f7767bc674efe0225a11982b4d /src
parent23ef4989ebaf960bfc9c71add9fd2c412e4ceca2 (diff)
downloadrspamd-05675bda7d2c8344f58679d7f66a904d30233c5d.tar.gz
rspamd-05675bda7d2c8344f58679d7f66a904d30233c5d.zip
[Minor] Allow to specify compression level for zstd
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 4d2758c5e..70236fc2f 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -364,7 +364,7 @@ LUA_FUNCTION_DEF (util, close_file);
LUA_FUNCTION_DEF (util, random_hex);
/***
- * @function util.zstd_compress(data)
+ * @function util.zstd_compress(data, [level=1])
* Compresses input using zstd compression
*
* @param {string/rspamd_text} data input data
@@ -2100,6 +2100,7 @@ lua_util_zstd_compress (lua_State *L)
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res, tmp;
gsize sz, r;
+ gint comp_level = 1;
if (lua_type (L, 1) == LUA_TSTRING) {
t = &tmp;
@@ -2114,6 +2115,10 @@ lua_util_zstd_compress (lua_State *L)
return luaL_error (L, "invalid arguments");
}
+ if (lua_type (L, 2) == LUA_TNUMBER) {
+ comp_level = lua_tointeger (L, 2);
+ }
+
sz = ZSTD_compressBound (t->len);
if (ZSTD_isError (sz)) {
@@ -2127,7 +2132,7 @@ lua_util_zstd_compress (lua_State *L)
res->start = g_malloc (sz);
res->flags = RSPAMD_TEXT_FLAG_OWN;
rspamd_lua_setclass (L, "rspamd{text}", -1);
- r = ZSTD_compress ((void *)res->start, sz, t->start, t->len, 1);
+ r = ZSTD_compress ((void *)res->start, sz, t->start, t->len, comp_level);
if (ZSTD_isError (r)) {
msg_err ("cannot compress data: %s", ZSTD_getErrorName (r));