zlib/gzip in lua?
Posted: Wed Feb 16, 2011 6:40 pm
Hey, I'm working on a Tiled map loader for love. I know there are a couple of other loaders out there but they're pretty basic and I'm aiming for full features/compatibility. Tiled can encode the map data into 5 formats: comma seperated value (CSV), base64, gzip, zlib, and XML. Currently I have all but gzip/zlib working and I'm having some trouble and was hoping the more technical-savvy people here could help me.
I have found http://lua-users.org/wiki/ModuleCompressDeflateLua which looks promising but it's very poorly documented (as in not at all). I've dug through the uncommented code for hours and I haven't really made any progress. It looks like you feed the gunzip function in deflatelua.lua a table with the fields "input" and "output". The input can be a string but the output has to be either a file or a function which handles bytes individually. I wrote a simple function that prints all bytes as characters but when i try and feed a gzip encoded string and the function to deflate.gunzip nothing happens. I simply get a cryptic "(no error message)"
Here is a sample gzip string:
H4sIAAAAAAAACw3DhwnAMAwAMP8P2Rdk9s1KoBQR2WK12R1Ol9vj9fn5A/luZ4Y4AAAA
which should be decoded to a base64 string:
jQAAAI4AAACPAAAAkAAAAJEAAACSAAAAkwAAAKEAAACiAAAAowAAAKQAAAClAAAApgAAAKcAAAA=
I'd really like to get the decompression working as everything else is nearly finished but this is above me. A little advice or guidance would be great.
I have found http://lua-users.org/wiki/ModuleCompressDeflateLua which looks promising but it's very poorly documented (as in not at all). I've dug through the uncommented code for hours and I haven't really made any progress. It looks like you feed the gunzip function in deflatelua.lua a table with the fields "input" and "output". The input can be a string but the output has to be either a file or a function which handles bytes individually. I wrote a simple function that prints all bytes as characters but when i try and feed a gzip encoded string and the function to deflate.gunzip nothing happens. I simply get a cryptic "(no error message)"
Here is a sample gzip string:
H4sIAAAAAAAACw3DhwnAMAwAMP8P2Rdk9s1KoBQR2WK12R1Ol9vj9fn5A/luZ4Y4AAAA
which should be decoded to a base64 string:
jQAAAI4AAACPAAAAkAAAAJEAAACSAAAAkwAAAKEAAACiAAAAowAAAKQAAAClAAAApgAAAKcAAAA=
I'd really like to get the decompression working as everything else is nearly finished but this is above me. A little advice or guidance would be great.