From 516e62eade2c310e63febc9493a9f19679db5db2 Mon Sep 17 00:00:00 2001 From: Xertis <118364459+Xertis@users.noreply.github.com> Date: Wed, 1 Oct 2025 00:56:39 +0300 Subject: [PATCH] Fix file.gzip --- src/logic/scripting/lua/libs/libfile.cpp | 28 ++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/logic/scripting/lua/libs/libfile.cpp b/src/logic/scripting/lua/libs/libfile.cpp index f5cb2bfc..191f6371 100644 --- a/src/logic/scripting/lua/libs/libfile.cpp +++ b/src/logic/scripting/lua/libs/libfile.cpp @@ -189,30 +189,26 @@ static int l_list(lua::State* L) { } static int l_gzip_compress(lua::State* L) { - std::vector bytes; + auto string = lua::bytearray_as_string(L, 1); - lua::read_bytes_from_table(L, 1, bytes); - auto compressed_bytes = gzip::compress(bytes.data(), bytes.size()); - int newTable = lua::gettop(L); + auto compressedBytes = gzip::compress( + reinterpret_cast(string.data()), + string.size() + ); - for (size_t i = 0; i < compressed_bytes.size(); i++) { - lua::pushinteger(L, compressed_bytes.data()[i]); - lua::rawseti(L, i + 1, newTable); - } + lua::create_bytearray(L, std::move(compressedBytes)); return 1; } static int l_gzip_decompress(lua::State* L) { - std::vector bytes; + auto string = lua::bytearray_as_string(L, 1); - lua::read_bytes_from_table(L, 1, bytes); - auto decompressed_bytes = gzip::decompress(bytes.data(), bytes.size()); - int newTable = lua::gettop(L); + auto decompressedBytes = gzip::decompress( + reinterpret_cast(string.data()), + string.size() + ); - for (size_t i = 0; i < decompressed_bytes.size(); i++) { - lua::pushinteger(L, decompressed_bytes.data()[i]); - lua::rawseti(L, i + 1, newTable); - } + lua::create_bytearray(L, std::move(decompressedBytes)); return 1; }