Converting gzip compressed and base64 encoded API response to string

I had to create a SignalR client because I wanted to try Bittrex websockets API, everything goes great until I receive responses from the API (Subscription data, simple calls, etc…) they state in the docs:

All responses are compressed by the server using GZip (via a ‘deflate’ API - there are no headers) and base64 encoded prior to transmission. Users must reverse this process to retrieve the JSON payload.

I’ve tried using :zlib.(gunzip, gzip, uncompress) just for the sake of it and they always return an error, obviously after decoding it with Base.decode64(). Example:

string = "jZC7DsIwDEX/xXOIEjuJ44w8tgKChgFQV36i6r+TvpAqQOAlUnR87OsW9pDgUm/zap03oOAAydrggoIbpHsL+Vo+FJwhiWWvnYyl4ATJaNOpEcEJCVGbqSYEQ4jMxDM5y5C18QvyJTMDEp2QtoiLeUguipcPpCEyTEIzGZiILXWNgrokKc9jCHTMJXC9qyr4srLVxJFLexlaWOvRcbSOXWTq5/4UDGsiY3/EvwQf7ipMTnrfm6Dpng=="

string |> Base.decode64!() |> :zlib.gunzip()

# This returns a :data_error from `:zlib`

Base.decode64!(string) 

<<141, 144, 187, 14, 194, 48, 12, 69, 255, 197, 115, 136, 18, 59, 137, 227, 140,
  60, 182, 2, 130, 134, 1, 80, 87, 126, 162, 234, 191, 147, 190, 144, 42, 64,
  224, 37, 82, 116, 124, 236, 235, 22, 246, 144, 224, 82, 111, 243, 106, 157,
  ...>>

In the other hand, it’s successfully decoded with Base and I get a binary which I’m not sure how to turn into a string but since the docs stated that it was compressed and all that I thought it was necessary to uncompress the data. I tried turning the binary to a string using other methods I found with no result.

:zlib.unzip/1 works.

2 Likes