2015-03-31 46 views
1

我正在使用cURL從GitLab使用其API下載存儲庫。所有這些都是使用PHP完成的。代碼如下:使用GitLab的API下載了GitLab存檔庫似乎已損壞

$zipResource = fopen('archive.zip', 'w'); 

$ch = curl_init("http://example.com/api/v3/projects"); 

curl_setopt($ch, CURLOPT_HTTPHEADER, array("PRIVATE-TOKEN: private_token_goes_here")); 

curl_setopt($ch, CURLOPT_URL, "http://example.com/api/v3/projects/64/repository/archive"); 

curl_setopt($ch, CURLOPT_FILE, $zipResource); 

curl_exec($ch); 

curl_close($ch); 

簡要概述:創建一個空的zip文件。連接到服務器,獲取存檔並將其寫入zip文件。

存檔出現在服務器上,我可以下載它,當我雙擊它時,我可以解壓縮它,所有文件都在那裏,一切似乎都是按順序的。

然而,當我嘗試使用終端以下錯誤彈出來將它解壓縮:

Archive: archive.ZIP 
    End-of-central-directory signature not found. Either this file is not 
    a zipfile, or it constitutes one disk of a multi-part archive. In the 
    latter case the central directory and zipfile comment will be found on 
    the last disk(s) of this archive. 

什麼我試過到目前爲止是:

設置標頭,"Content-type: application/zip"。將標題設置爲"Content-Transfer-Encoding: Binary"(歸檔文件類型爲'wb' //binary)或"Content-type: application/octet-stream"等等。最終結果總是相同的,這意味着當試圖解壓縮壓縮文件時會出現上述錯誤。

我只能假設我要麼沒有正確使用cURL,沒有正確設置標題,或者他們的API出現問題(極不可能)。

任何在正確的方向推動非常感謝。

回答

0

我遇到了與Gitlab相同的問題。在我的情況下下載tar作爲罰款。我還發現下載的ZIP文件實際上包含所有數據,但已損壞。如果安裝了Java,ZIP文件的數據仍然可以恢復:

jar xvf corrupted-zip-file.zip 
+0

那麼這可能是他們的api /後端系統創建zip文件的錯誤:D – hanshenrik 2015-10-14 09:38:26