Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle the packed string on Ruby server side? #23

Open
patakijv opened this issue Sep 10, 2022 · 0 comments
Open

How to handle the packed string on Ruby server side? #23

patakijv opened this issue Sep 10, 2022 · 0 comments

Comments

@patakijv
Copy link

If I create a packedString of a JSON object using JSONC as so:

var packedString = JSONC.pack(JSONObject)

Then I send this packedString to a Ruby on Rails server and try to "unpack" it back to the JSON object, I am running into problems.
I've tried in controller action

packed_string = params["packedString"]
gz = Zlib::GzipReader.new(StringIO.new(packed_string)) # errors out here with Zlib::GzipFile::Error: not in gzip format
uncompressed_string = gz.read
json = JSON.parse(uncompressed_string)

I've also tried to decode it first thinking the issue is that it is in base64 encoded format

packed_string = params["packedString"]
decoded_string = Base64.decode64(packed_string)
gz = Zlib::GzipReader.new(StringIO.new(decoded_string)) # errors out here with Zlib::GzipFile::Error: not in gzip format
uncompressed_string = gz.read
json = JSON.parse(uncompressed_string)

But in both cases Zlib::GzipReader doesn't think it is receiving something in a gzip format with the error message: Zlib::GzipFile::Error: not in gzip format

What should be done to properly unpack this on Ruby on Rails serve side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant