diff options
-rw-r--r-- | include/Handle.h | 2 | ||||
-rw-r--r-- | lib/Handle.cc | 10 | ||||
-rw-r--r-- | lib/LuaHandle.cc | 10 |
3 files changed, 14 insertions, 8 deletions
diff --git a/include/Handle.h b/include/Handle.h index b5ae977..7418655 100644 --- a/include/Handle.h +++ b/include/Handle.h @@ -80,7 +80,7 @@ class Handle : public Base { static int GetNbHandles(); static int zlib_inflate(Handle * in, Handle * out) throw (GeneralException); - static int zlib_deflate(Handle * in, Handle * out) throw (GeneralException); + static int zlib_deflate(Handle * in, Handle * out, int level = Z_DEFAULT_COMPRESSION, bool raw = false) throw (GeneralException); #ifdef HAVE_UCL static int ucl_compress(Handle * in, Handle * out, int len_in = -1) throw (GeneralException); static int ucl_decompress(Handle * in, Handle * out, unsigned int len_out, int len_in = -1) throw (GeneralException); diff --git a/lib/Handle.cc b/lib/Handle.cc index 457f2c9..e88663a 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -887,8 +887,8 @@ int Handle::zlib_inflate(Handle * in, Handle * out) throw (GeneralException) { have = total_out = 0; ret = inflateInit(&s); - if (ret != Z_OK ) { - throw GeneralException("zlib: deflateInit() failed: " + String(ret)); + if (ret != Z_OK) { + throw GeneralException("zlib: inflateInit() failed: " + String(ret)); } do { @@ -927,7 +927,7 @@ int Handle::zlib_inflate(Handle * in, Handle * out) throw (GeneralException) { return total_out; } -int Handle::zlib_deflate(Handle * in, Handle * out) throw (GeneralException) { +int Handle::zlib_deflate(Handle * in, Handle * out, int level, bool raw) throw (GeneralException) { int ret, flush; z_stream s; unsigned char b_in[CHUNK]; @@ -944,8 +944,8 @@ int Handle::zlib_deflate(Handle * in, Handle * out) throw (GeneralException) { have = total_out = 0; - ret = deflateInit(&s, Z_DEFAULT_COMPRESSION); - if (ret != Z_OK ) { + ret = deflateInit2(&s, level, Z_DEFLATED, raw ? -15 : 15, 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) { throw GeneralException("zlib: deflateInit() failed: " + String(ret)); } diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc index 207c4e7..789876e 100644 --- a/lib/LuaHandle.cc +++ b/lib/LuaHandle.cc @@ -829,15 +829,21 @@ int sLuaHandle::zlib_deflate(lua_State * __L) { int n = L->gettop(); Handle * s, * d; int r; + int level = Z_DEFAULT_COMPRESSION; + bool raw = false; - if (n != 2) { + if ((n < 2) || (n > 4) || ((n >= 3) && !L->isnumber()) || ((n == 4) && !L->isboolean())) { L->error("Incorrect arguments to method `Handle::zlib_deflate'"); } s = L->recast<Handle>(1); d = L->recast<Handle>(2); + if (n >= 3) + level = L->tonumber(3); + if (n == 4) + raw = L->toboolean(4); - r = Handle::zlib_deflate(s, d); + r = Handle::zlib_deflate(s, d, level, raw); L->push((lua_Number) r); |