Fix file.gzip

This commit is contained in:
Xertis 2025-10-01 00:56:39 +03:00 committed by GitHub
parent 209479be46
commit 516e62eade
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -189,30 +189,26 @@ static int l_list(lua::State* L) {
} }
static int l_gzip_compress(lua::State* L) { static int l_gzip_compress(lua::State* L) {
std::vector<ubyte> bytes; auto string = lua::bytearray_as_string(L, 1);
lua::read_bytes_from_table(L, 1, bytes); auto compressedBytes = gzip::compress(
auto compressed_bytes = gzip::compress(bytes.data(), bytes.size()); reinterpret_cast<const ubyte*>(string.data()),
int newTable = lua::gettop(L); string.size()
);
for (size_t i = 0; i < compressed_bytes.size(); i++) { lua::create_bytearray(L, std::move(compressedBytes));
lua::pushinteger(L, compressed_bytes.data()[i]);
lua::rawseti(L, i + 1, newTable);
}
return 1; return 1;
} }
static int l_gzip_decompress(lua::State* L) { static int l_gzip_decompress(lua::State* L) {
std::vector<ubyte> bytes; auto string = lua::bytearray_as_string(L, 1);
lua::read_bytes_from_table(L, 1, bytes); auto decompressedBytes = gzip::decompress(
auto decompressed_bytes = gzip::decompress(bytes.data(), bytes.size()); reinterpret_cast<const ubyte*>(string.data()),
int newTable = lua::gettop(L); string.size()
);
for (size_t i = 0; i < decompressed_bytes.size(); i++) { lua::create_bytearray(L, std::move(decompressedBytes));
lua::pushinteger(L, decompressed_bytes.data()[i]);
lua::rawseti(L, i + 1, newTable);
}
return 1; return 1;
} }