diff options
author | Pixel <pixel@nobis-crew.org> | 2010-06-20 20:51:57 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2010-06-20 20:51:57 -0700 |
commit | 8abf31744c41eacee7ea835aca7866735a30a4f0 (patch) | |
tree | b70a65cf27c388c685ceadd00b3272e6123f4c9d /lib | |
parent | ecb115ec57dcf948262731ff929101647a5f0741 (diff) |
Adding levels and ability to raw-compress in zlib_deflate.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Handle.cc | 10 | ||||
-rw-r--r-- | lib/LuaHandle.cc | 10 |
2 files changed, 13 insertions, 7 deletions
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); |