commit 05675bd: [Minor] Allow to specify compression level for zstd
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Jun 29 13:49:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-06-29 14:20:31 +0100
URL: https://github.com/rspamd/rspamd/commit/05675bda7d2c8344f58679d7f66a904d30233c5d
[Minor] Allow to specify compression level for zstd
---
src/lua/lua_util.c | 9 +++++++--
1 file 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));
More information about the Commits
mailing list