Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,10 +1609,13 @@ static int l_Deflate(lua_State* L)
int n = lua_gettop(L);
ui->LAssert(L, n >= 1, "Usage: Deflate(string)");
ui->LAssert(L, lua_isstring(L, 1), "Deflate() argument 1: expected string, got %s", luaL_typename(L, 1));
ui->LAssert(L, lua_isboolean(L, 2) || lua_isnil(L, 2) || lua_isnone(L, 2), "Deflate() argument 2: expected boolean or nil, got %s", luaL_typename(L, 2));
bool isGzip = lua_toboolean(L, 2);
z_stream_s z;
z.zalloc = NULL;
z.zfree = NULL;
deflateInit(&z, 9);
// Adding 16 enables Gzip headers instead of ZLib headers
deflateInit2(&z, Z_BEST_COMPRESSION, Z_DEFLATED, MAX_WBITS + (isGzip ? 16 : 0), 8, Z_DEFAULT_STRATEGY);
size_t inLen;
byte* in = (byte*)lua_tolstring(L, 1, &inLen);
// Prevent deflation of input data larger than 128 MiB.
Expand Down Expand Up @@ -1666,7 +1669,8 @@ static int l_Inflate(lua_State* L)
z.zfree = NULL;
z.next_out = out.data();
z.avail_out = outSz;
inflateInit(&z);
// Adding 32 enables automatic detection of headers
inflateInit2(&z, MAX_WBITS + 32);
int err;
while ((err = inflate(&z, Z_NO_FLUSH)) == Z_OK) {
// Output buffer filled, try to embiggen it.
Expand Down
Loading