Gzip compression

Is there a way to gzip compress data in Lua in a similar manner to PostAsync?

I’m keen to gzip my data prior to posting it, as having the compressed string gives me more options for encrypting the data,

Has anyone had any luck performing this in Lua?

Summary

From PostAsync’s documentation

string PostAsync (
    string url,
    string data,
    HttpContentType content_type = ApplicationJson,
    bool compress = false, <--
    dictionary headers = nil
)

Compression uses gzip. If you set the compress parameter to true, your data will be gzipped.

Just pass true as the third argument.

Oh shoot I misread, nvm.

Thanks for your message.

What I’m talking about is obtaining the compressing outside of PostAsyc, giving me the compressed string.

This would give me a lot more flexibility in how I post and authenticate my data.

I imagine this isn’t possible to do in Lua however?

Right, my bad.

I would probably use JSONEncode on my table to convert it into JSON, and then use an open-source gzip script to compress it. And then encode the result into Base64.

EDIT: This seems promising: https://github.com/Rochet2/lualzw. I’m not sure that the algorithm is gzip, however EDITEDIT: It’s not gzip, sadly.

Huh. looking for a gzip library was harder than I thought.

I suspect that Lua would do a poor job of handling it efficiently.

I found a gzip module. This might help: https://github.com/davidm/lua-compress-deflatelua/blob/master/lmod/compress/deflatelua.lua . (edit: nevermind, the interface permits strings)

EDIT: Actually, ignore this. Compression isn’t implemented in that module :confused:

I’d say keep your fingers crossed that @zeuxcg follows this up!

1 Like

Also keep in mind, if you do compress your data in Lua, I don’t think you’ll be able to use PostAsync due to the fact that you cannot set the gzip header (to indicate to the server that your data is compressed)

1 Like