无法在Octokit.net中将存储库内容作为.zip文件(zipball)获取

时间:2015-04-21 08:33:34

标签: c# .net zip github-api octokit.net

我使用Octokit.net version 0.9.0(GitHub API for .NET)来获取少量存储库的zip内容。

我已经拥有了我需要的存储库列表但是我无法将存储库的内容作为.zip文件(称为zipball)获取

到目前为止我尝试了什么

// ... client = new Client(...);
// some authentication logic...
// some other queries to GitHub that work correctly
var url = "https://api.github.com/repos/SomeUser/SomeRepo/zipball";
var response = await this.client.Connection.Get<byte[]>(
        new Uri(url),
        new Dictionary<string, string>(),
        null);
var data = response.Body;
var responseData = response.HttpResponse.Body;

我尝试的问题

  1. data为空
  2. responseData.GetType().Name表示responseData的类型为字符串
  3. 当我尝试Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString());时,我收到无效的zip文件
  4. Value of response.HttpResponse.Body

    Quesion

    使用Octokit.net库进行身份验证后获取存储库的zipball的正确方法是什么?

    我还在octokit.net资源库中打开了an issue

1 个答案:

答案 0 :(得分:2)

在检查了Octokit的来源后,我认为这是不可能的(从版本0.10.0开始):

请参阅Octokit\Http\HttpClientAdapter.cs

function Print(){
    onPrintBegin
    window.print();
    onPrintFinish(); 
}

响应主体(// We added support for downloading images. Let's constrain this appropriately. if (contentType == null || !contentType.StartsWith("image/")) { responseBody = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); } else { responseBody = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false); } )被转换为unicode字符串,因此它被破坏而不是二进制相同。请参阅我的PR792(需要用responseData替换if语句)来修复此问题(然后它是一个字节数组。可以使用if (contentType == null || (!contentType.StartsWith("image/") && !contentType.StartsWith("application/")))编写。)