MCPcopy Create free account
hub / github.com/defold/defold / Zlib_Deflate

Function Zlib_Deflate

engine/script/src/script_zlib.cpp:114–134  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 7

DeflateBufferFunction · 0.85
lua_pushlstringFunction · 0.85
luaL_errorFunction · 0.85
assertFunction · 0.50
SetCapacityMethod · 0.45
BeginMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected