title: Zlib Inflate data from http packet
body: <p>I'm trying to use zlib's inflate to decompress some data I received from an http packet.</p>
  
  <p>The packet is as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/R0bvo.png" alt="enter image description here"></p>
  
  <p>The packet, itself, says that it's encoded with gzip, so I think it should work. However, when I run the data through the inflate function, I get "invalid block type". To be clear, I'm only passing in the highlighted portion of the packet to the inflate function. What am I missing?</p>
  
  <p>Here is the code I'm using to decompress the data:</p>
  
  <pre><code>int Decompress(const u_char* strStreamIn, int nStreamInLen, u_char* strStreamOut)
  {
    int ret = -1;
    int err = -1;
  
    z_stream strm  = {0};
    strm.total_in  = strm.avail_in  = nStreamInLen;
    strm.total_out = strm.avail_out = nStreamInLen * 6;
    strm.next_in   = (Bytef*) strStreamIn;
    strm.next_out  = (Bytef*) strStreamOut;
    strm.zalloc    = Z_NULL;
    strm.zfree     = Z_NULL;
    strm.opaque    = Z_NULL;
  
    err = inflateInit2(&amp;strm, -MAX_WBITS);
    if (err == Z_OK) {
      err = inflate(&amp;strm, Z_FINISH);
      if (err == Z_STREAM_END) {
        ret = strm.total_out;
      }
      else {
        inflateEnd(&amp;strm);
        return err;
      }
    }
    else {
      inflateEnd(&amp;strm);
      return err;
    }
    inflateEnd(&amp;strm);
    return ret;  
  }
  </code></pre>