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;
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) {
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