title: iPhone and GZip
body: <p>Now I know that xCode automaticly does the GZip decrompession for you within:</p>
  
  <pre><code>NSData *data = [NSData dataWithContentsOfURL:URL];
  </code></pre>
  
  <p>And it does work if I point to a Gzip file on my server. But since my content is dynamic, I have a PHP script that rather then create a gzip file like so:</p>
  
  <pre><code>$zp   = gzopen($file, "r");
  $data = gzread($zp, $filesize);
  gzclose($zp);
  </code></pre>
  
  <p>I encode my own data with:</p>
  
  <pre><code>echo gzencode($data, 9);
  </code></pre>
  
  <p>With this I add the following headers:</p>
  
  <pre><code>header("Content-Type: application/x-gzip");
  header("Content-Encoding: gzip");
  header("Accepts-Encoding: gzip");
  </code></pre>
  
  <p>When I browse to the URL, my browser wants to download the file automatically and I am able to unzip it on my Mac and view it's content. However when I try to read it through xCode it won't work.</p>
  
  <pre><code>NSData *data = [NSData dataWithContentsOfURL:URL];
  NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  NSLog (content); //returns only data when pointed directly to a Gzip file
  </code></pre>
  
  <p>Am I forgetting something?</p>