title: Elixir - Converting gzip compressed and base64 encoded API response to string
body: <p>I had to create a SignalR client because I wanted to try Bittrex websockets API, everything went great until I receive responses from the API (Subscription data, simple calls, etc...) they state in the <a href="https://bittrex.github.io/" rel="nofollow noreferrer">docs</a>:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I've tried using <code>:zlib.(gunzip, gzip, uncompress)</code> just for the sake of it and they always return an error, obviously after decoding it with <code>Base.decode64()</code>. Example:</p>
  
  <pre><code>string = "jZC7DsIwDEX/xXOIEjuJ44w8tgKChgFQV36i6r+TvpAqQOAlUnR87OsW9pDgUm/zap03oOAAydrggoIbpHsL+Vo+FJwhiWWvnYyl4ATJaNOpEcEJCVGbqSYEQ4jMxDM5y5C18QvyJTMDEp2QtoiLeUguipcPpCEyTEIzGZiILXWNgrokKc9jCHTMJXC9qyr4srLVxJFLexlaWOvRcbSOXWTq5/4UDGsiY3/EvwQf7ipMTnrfm6Dpng=="
  
  string |&gt; Base.decode64!() |&gt; :zlib.gunzip()
  
  # This returns a :data_error from `:zlib`
  
  Base.decode64!(string) 
  
  &lt;&lt;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,
    ...&gt;&gt;
  </code></pre>
  
  <p>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.</p>