summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-07-01 19:49:24 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-07-01 19:49:24 +0200
commitecf0de245cba43276df7ac4a9410361e0346a2a0 (patch)
tree4bd20b9310ee026e0af1894bf3d85232f181dfeb
parent556aa54bfdfdc72c49a9ea705fe81c03f596c732 (diff)
Adding gzip generation from zlib_deflate.
-rw-r--r--include/Handle.h2
-rw-r--r--lib/Handle.cc4
-rw-r--r--lib/LuaHandle.cc9
3 files changed, 9 insertions, 6 deletions
diff --git a/include/Handle.h b/include/Handle.h
index 7418655..1aca644 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, int level = Z_DEFAULT_COMPRESSION, bool raw = false) throw (GeneralException);
+ static int zlib_deflate(Handle * in, Handle * out, int level = Z_DEFAULT_COMPRESSION, bool raw = false, bool gzip = 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 e88663a..39bc981 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -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, int level, bool raw) throw (GeneralException) {
+int Handle::zlib_deflate(Handle * in, Handle * out, int level, bool raw, bool gzip) throw (GeneralException) {
int ret, flush;
z_stream s;
unsigned char b_in[CHUNK];
@@ -944,7 +944,7 @@ int Handle::zlib_deflate(Handle * in, Handle * out, int level, bool raw) throw (
have = total_out = 0;
- ret = deflateInit2(&s, level, Z_DEFLATED, raw ? -15 : 15, 8, Z_DEFAULT_STRATEGY);
+ ret = deflateInit2(&s, level, Z_DEFLATED, gzip ? 31 : (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 5b0d85e..08f4911 100644
--- a/lib/LuaHandle.cc
+++ b/lib/LuaHandle.cc
@@ -831,8 +831,9 @@ int sLuaHandle::zlib_deflate(lua_State * __L) {
int r;
int level = Z_DEFAULT_COMPRESSION;
bool raw = false;
+ bool gzip = false;
- if ((n < 2) || (n > 4) || ((n >= 3) && !L->isnumber(3)) || ((n == 4) && !L->isboolean(4))) {
+ if ((n < 2) || (n > 5) || ((n >= 3) && !L->isnumber(3)) || ((n >= 4) && !L->isboolean(4)) || ((n >= 5) && !L->isboolean(5))) {
L->error("Incorrect arguments to method `Handle::zlib_deflate'");
}
@@ -840,10 +841,12 @@ int sLuaHandle::zlib_deflate(lua_State * __L) {
d = L->recast<Handle>(2);
if (n >= 3)
level = L->tonumber(3);
- if (n == 4)
+ if (n >= 4)
raw = L->toboolean(4);
+ if (n >= 5)
+ gzip = L->toboolean(5);
- r = Handle::zlib_deflate(s, d, level, raw);
+ r = Handle::zlib_deflate(s, d, level, raw, gzip);
L->push((lua_Number) r);