title: iPhone Unzip code
body: <p>Really stuck on trying to write code to unzip a file or directory on the iPhone.</p>
  
  <p>Below is some sample code that I'm using to try and unzip a simple text file. </p>
  
  <p>It unzips the file but its corrupt.</p>
  
  <pre><code>(void)loadView {
  
      NSString *DOCUMENTS_FOLDER = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
      NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"sample.zip"];
  
      NSString *unzipeddest = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"test.txt"];  
  
      gzFile file = gzopen([path UTF8String], "rb");
  
      FILE *dest = fopen([unzipeddest UTF8String], "w");
  
      unsigned char buffer[CHUNK];
  
      int uncompressedLength = gzread(file, buffer, CHUNK);
  
      if(fwrite(buffer, 1, uncompressedLength, dest) != uncompressedLength ||     ferror(dest)) {
          NSLog(@"error writing data");
      }
      else{
  
      }
  
      fclose(dest);
      gzclose(file);  
  }
  </code></pre>