Deflate (compress) a buffer * A lua error is raised is on error * * @name zlib.deflate * @param buf [type:string] buffer to deflate * @return buf [type:string] deflated buffer * @examples * * ```lua * local data = "This is a string with uncompressed data." * local compressed_data = zlib.deflate(data) * local s = "" * for c in string.gmatc
| 112 | * ``` |
| 113 | */ |
| 114 | int Zlib_Deflate(lua_State* L) |
| 115 | { |
| 116 | dmArray<uint8_t> out; |
| 117 | out.SetCapacity(32 * 1024); |
| 118 | const char* in = luaL_checkstring(L, 1); |
| 119 | int in_len = lua_strlen(L, 1); |
| 120 | dmZlib::Result r = dmZlib::DeflateBuffer(in, in_len, 3, &out, Writer); |
| 121 | if (r == dmZlib::RESULT_OK) |
| 122 | { |
| 123 | lua_pushlstring(L, (const char*) out.Begin(), out.Size()); |
| 124 | return 1; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | luaL_error(L, "Failed to deflate buffer (%d)", r); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | assert(0); // never reached |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static const luaL_reg ScriptZlib_methods[] = |
| 137 | { |
nothing calls this directly
no test coverage detected