Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I GZIP a string?

Asked by
GShocked 150
8 years ago

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.

ImgScript = {}
for index, child in pairs(workspace.IMG:GetChildren()) do
    table.insert(ImgScript, child.BrickColor.Number)
end

h = game:GetService'HttpService'
ImgScript = h:JSONEncode(ImgScript) --Convert to JSON

api_dev_key = 'MyPastebinAPIDeveloperKey'
api_paste_code = ImgScript
api_paste_private = '1'
api_paste_name = 'TEST' 
api_paste_expire_date = 'N'
api_paste_format = 'lua'
api_user_key = ''
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = 'MyPastebinUsername'
password = 'MyPastebinPassword'

api_user_key = h:PostAsync(
    'http://pastebin.com/api/api_login.php',
    'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
    2
)
print(api_user_key)
final = h:PostAsync(
    'http://pastebin.com/api/api_post.php',
    '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 ,
    2
)
print(final)

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.

Answer this question