1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add zstd compression support (#12515)

This commit is contained in:
20kdc 2022-09-28 14:06:14 +01:00 committed by GitHub
parent 0251b01da6
commit b1233056b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 13 deletions

View file

@ -80,3 +80,26 @@ unittests.register("test_punch_node", function(_, pos)
minetest.remove_node(pos)
-- currently failing: assert(on_punch_called)
end, {map=true})
local function test_compress()
-- This text should be compressible, to make sure the results are... normal
local text = "The\000 icey canoe couldn't move very well on the\128 lake. The\000 ice was too stiff and the icey canoe's paddles simply wouldn't punch through."
local methods = {
"deflate",
"zstd",
-- "noodle", -- for warning alarm test
}
local zstd_magic = string.char(0x28, 0xB5, 0x2F, 0xFD)
for _, method in ipairs(methods) do
local compressed = core.compress(text, method)
assert(core.decompress(compressed, method) == text, "input/output mismatch for compression method " .. method)
local has_zstd_magic = compressed:sub(1, 4) == zstd_magic
if method == "zstd" then
assert(has_zstd_magic, "zstd magic number not in zstd method")
else
assert(not has_zstd_magic, "zstd magic number in method " .. method .. " (which is not zstd)")
end
end
end
unittests.register("test_compress", test_compress)