title: C++ Inflate gzip char array
body: <p>I'm attempting to use zlib to uncompress (inflate) some IP packet payload data that is compressed via gzip. However, I'm having some difficultly understanding some of the documentation provided by zlib that covers inflation. I have a char array that my program fills but I can't seem to inflate it with the following code:</p>
  
  <pre><code>const u_char payload; /*contains gzip data, 
                        captured prior to this point in the program*/
  
  /*read compressed contents*/
  int ret; //return val
  z_stream stream;
  unsigned char out[MEM_CHUNK]; //output array, MEM_CHUNK defined as 65535
  
  /* allocate inflate state */
  stream.zalloc = Z_NULL;
  stream.zfree = Z_NULL;
  stream.opaque = Z_NULL;
  stream.avail_in = size_payload; // size of input
  stream.next_in = (Bytef *)payload; // input char array
  stream.avail_out = (uInt)sizeof(out); // size of output
  stream.next_out = (Bytef *)out; // output char array
  
  ret = inflateInit(&amp;stream);
  inflate(&amp;stream, Z_NO_FLUSH);
  inflateEnd(&amp;stream);
  
  printf("Inflate: %s\n\n", out);
  </code></pre>
  
  <p>In the <a href="http://www.zlib.net/zlib_how.html" rel="nofollow">zlib documentation</a>, they have inflate continually called via a do/while loop, checking for the Z_STREAM_END flag. I'm a bit confused here, because it seems they're working from a file while I'm not. Do I need this loop as well, or am I able to provide a char array without looping over inflate?</p>
  
  <p>Any guidance here would really be appreciated. I'm pretty new to both working with compression and C++.</p>
  
  <p>Thanks. </p>