无法获得资料库的内容作为Octokit.net .zip文件(zipball) [英] Cannot get repository contents as .zip file (zipball) in Octokit.net

查看:197
本文介绍了无法获得资料库的内容作为Octokit.net .zip文件(zipball)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Octokit.net 0.9.0版本(用于.NET的GitHub API)获取一些资源库拉链内容。

我已经有仓库,我需要的清单,但我有获取信息库的.zip文件的内容的麻烦(称为zipball)

我到目前为止已经试过

  // ...客户端=新的客户端(...);
//一些认证逻辑...
//一些其他的查询GitHub上的正常工作
VAR URL =htt​​ps://api.github.com/repos/SomeUser/SomeRepo/zipball;
VAR响应=等待this.client.Connection.Get< byte []的>(
        新的URI(URL),
        新的字典<字符串,字符串>()
        空值);
VAR数据= response.Body;
VAR responseData = response.Htt presponse.Body;
 

我的企图问题。

  1. 数据为null
  2. responseData.GetType()。名称表示, responseData 为字符串类型
  3. 当我尝试 Encoding.ASCII.GetBytes(response.Htt presponse.Body.ToString()); 我得到无效的压缩文件

Quesion

什么是正确的方式使用Octokit.net库的认证之后获得的存储库zipballs?

我也开在octokit.net库的问题

解决方案

检查Octokit源后,我觉得这是不可能的(为0.10.0版本):

请参阅 Octokit \ HTTP \ HttpClientAdapter的.cs

  //我们增加了对下载图像的支持。让我们适当地限制这一点。
如果(的contentType == NULL ||!contentType.StartsWith(图像/))
{
    responseBody =等待responseMessage.Content.ReadAsStringAsync()ConfigureAwait(假)。
}
其他
{
    responseBody =等待responseMessage.Content.ReadAsByteArrayAsync()ConfigureAwait(假)。
}
 

响应体( responseData )转换为单code字符串,因此,这是错位的,而不是二进制相同。见我 PR792 (需要更换,如果语句如果(的contentType == NULL ||(contentType.StartsWith(图像/)及!&安培;!contentType.StartsWith(应用程序/))))来解决这个问题(当时它是一个。字节数组编写可能使用 System.IO.File.WriteAllBytes(C:\\ test.zip(字节[])responseData);

I am using Octokit.net version 0.9.0 (GitHub API for .NET) for getting zip contents of few repositories.

I already have the list of repositories I need but I am having trouble with getting the the content of the repositories as .zip files (called zipball)

What I've tried so far

// ... 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;

Problems with my attempts

  1. data is null
  2. responseData.GetType().Name says the responseData is of type string
  3. When I try Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString()); I get invalid zip file

Quesion

What is the correct way to get zipballs of repositories after being authenticated using Octokit.net library?

I've also opened an issue in octokit.net repository.

解决方案

After checking the source of Octokit I think this is not possible (as of version 0.10.0):

See Octokit\Http\HttpClientAdapter.cs

// 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);
}

The response body (responseData) is converted to an unicode string and, thus, it's mangled and not binary the same. See my PR792 (need to replace the if statement with if (contentType == null || (!contentType.StartsWith("image/") && !contentType.StartsWith("application/")))) to fix this (then it's a byte array. Writing possible using System.IO.File.WriteAllBytes("c:\\test.zip", (byte[])responseData);).

这篇关于无法获得资料库的内容作为Octokit.net .zip文件(zipball)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆