本文介绍了codeload.github.com与api.github.com有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览 next.js 存储库,并注意到此功能使用tar从GitHub下载并提取模板:

I was browsing the next.js repository and noticed this function that downloads and extracts a template from GitHub, with tar:

export async function downloadAndExtractExample(
  root: string,
  name: string
): Promise<void> {
  return await promisePipe(
    got.stream('https://codeload.github.com/zeit/next.js/tar.gz/canary'),
    tar.extract({ cwd: root, strip: 3 }, [`next.js-canary/examples/${name}`])
  )
}

我在StackOverflow上进行了搜索,但我只发现了这一点:

I searched on StackOverflow and I only found this:

这是一个线程,解释了如何从GitHub中提取tar.gz,但是没有提到"codeload"子域.与"api"有何不同?

That's a thread explaining how you can pull a tar.gz from GitHub, but there is no mention of the "codeload" subdomain. How is it different to "api"?

推荐答案

GitHub API提供了获取URL来下载档案的最佳方法.当您对该URL发出GET请求时,它将把您重定向到codeload.github.com上的URL. codeload是一项提供存档下载的服务,出于缓存原因,它位于自己的域中.

The GitHub API provides the best way to get a URL to download an archive. When you make a GET request on that URL, it will redirect you to a URL on codeload.github.com. codeload is the service which provides archives for download and it's on its own domain for caching reasons.

虽然可以直接使用代码加载URL,但您通常要使用API​​ URL,因为它可以更轻松地处理身份验证之类的事情,并且私有存储库的代码加载URL通常是短暂的.

While it's possible to use the codeload URL directly, you generally want to use the API URL, since it handles things like authentication more gracefully, and the codeload URLs for private repositories are generally ephemeral.

这篇关于codeload.github.com与api.github.com有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 15:35