title: Private repository archive(tar.gz) from GitLab, downloaded using PHP via GitLab's API, appears to be corruputed - invalid checksum
body: <p>I want to download a private GitLab repository archive using their API. I'm using PHP and cURL to do that. I'm able to do so using the following code:</p>
  
  <pre><code>$ch = curl_init(http://example.com/api/v3/projects/64/repository/archive?private_token=private_token_goes_here);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  
  $output = curl_exec($ch);
  $fh = fopen("out.tar.gz", 'w');
  fwrite($fh, $output);
  fclose($fh);
  </code></pre>
  
  <p>The code itself is nothing complicated and pretty standard.</p>
  
  <p>The issue I'm facing is that once I try to unpack, using the code bellow: </p>
  
  <pre><code>    // decompress from gz
      $p = new PharData($temp_archive . '.tar.gz');
      $p-&gt;decompress($temp_archive . '.tar');
  
      // unarchive from the tar
      $phar = new PharData($temp_archive . '.tar');
      $phar-&gt;extractTo($extract_path);
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'UnexpectedValueException' with message ' in phpfile.php on line 294
  
  UnexpectedValueException: phar error: "path/to/downloaded/archive/temp_archive.tar.gz" is a corrupted tar file (checksum mismatch of file "52 comment=01607149cd460cba6f1ac3003bb7b0c9cb0e2b94
  ") in phpfile.php on line 294
  </code></pre>
  
  <p>Yes, that is the whole error, I didn't cut out the error message. The <code>'</code> is the error message.</p>
  
  <p>The checksum for the downloaded file is, indeed, invalid. After a few good hours of Googling and forum browsing I'm back to square one. I have no idea what's wrong with it.</p>
  
  <p>If I was to untar the archive using a terminal(I'm on MAC OS Build 12E55), it will unpack normally. The files are all there and I receive no errors what-so-ever.</p>
  
  <p>I tried manually downloading the archive from GitLab and unpacking it using PHP(I get the same error). </p>
  
  <p>I tried creating a *.tar.gz file using a terminal and unpacking it using PHP(I receive no errors and the unpacking proceeds normally). </p>
  
  <p>I tried uploading a file created using the terminal and downloading it using PHP, after which I unpacked it, again using PHP, and I receive no errors.</p>
  
  <p>I can only assume that I'm either:</p>
  
  <ul>
  <li>Not using their API properly</li>
  <li>Not setting the right headers - although I had tried setting:
  <ol>
  <li>Content-Type: application/octet-stream</li>
  <li>Content-Type: application/x-tar</li>
  <li>Content-Transfer-Encoding: binary...and so on. When using the binary header, the file that I put the content in was set to <code>'wb'</code>. Still, no luck.</li>
  </ol></li>
  </ul>
  
  <p>And lastly it could be that their API may not be working properly, although I doubt it.</p>
  
  <p>And nudging in the right direction is greatly appreciated.</p>