How do I GZIP a string?
I have the following script; It basically collects the BrickColor Numbers of parts in a model, puts them into a table, converts them to JSON, and uploads them to Pastebin.
02 | for index, child in pairs (workspace.IMG:GetChildren()) do |
03 | table.insert(ImgScript, child.BrickColor.Number) |
06 | h = game:GetService 'HttpService' |
07 | ImgScript = h:JSONEncode(ImgScript) |
09 | api_dev_key = 'MyPastebinAPIDeveloperKey' |
10 | api_paste_code = ImgScript |
11 | api_paste_private = '1' |
12 | api_paste_name = 'TEST' |
13 | api_paste_expire_date = 'N' |
14 | api_paste_format = 'lua' |
16 | api_paste_name = h:UrlEncode(api_paste_name) |
17 | api_paste_code = h:UrlEncode(api_paste_code) |
18 | username = 'MyPastebinUsername' |
19 | password = 'MyPastebinPassword' |
21 | api_user_key = h:PostAsync( |
23 | 'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password, |
29 | 'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code , |
This doesn't work for all uploads. It returns 'Bad API Request, invalid api_option' when I try this particular script.
This DOES work when the api_paste_code (the content of the paste) is something small like "Testing this api here". So I assume that this is because PostAsync data larger than 256 bytes has to be GZIPed before it is sent, afterward it can be up to 1024kb (1mb).
So how would I GZIP my data?
PS: I've also tried encoding it in base64 to make sure this problem isn't with spaces and symbols.