从GitHub repo下载单个文件有哪些技巧?
我不想要显示原始文件的URL;对于二进制文件,什么都没有。
http://support.github.com/discussions/feature-requests/41-download-single-file
是否有可能将GitHub用作“下载服务器”?
如果我们决定切换到GoogleCode,是否提供了上述功能?
或者开源项目是否有免费托管和VCS?
从GitHub repo下载单个文件有哪些技巧?
我不想要显示原始文件的URL;对于二进制文件,什么都没有。
http://support.github.com/discussions/feature-requests/41-download-single-file
是否有可能将GitHub用作“下载服务器”?
如果我们决定切换到GoogleCode,是否提供了上述功能?
或者开源项目是否有免费托管和VCS?
当前回答
或者试试这个
const https = require('https');
const fs = require('fs');
const DOMAIN = 'raw.githubusercontent.com';
function writeFile(data, fileName) {
fs.appendFile(fileName, data.toString(), err => {
if (err) {
console.log('error in writing file', err);
}
});
}
function EOF(data) {
console.log('EOF');
}
function getFileName(pathToFile) {
var result = pathToFile.split('/');
var splitLength = result.length;
return result[splitLength - 1];
}
function getFile(branchName, username, repoName, ...pathToFile) {
pathToFile.forEach(item => {
const path = `/${username}/${repoName}/${branchName}/${item}`;
const URL = `${DOMAIN}${path}`;
const options = {
hostname: DOMAIN,
path: path
};
var fileName = getFileName(item);
https
.get(options, function(res) {
console.log(res.statusCode);
/* if file not found */
if (res.statusCode === 404) {
console.log('FILE NOT FOUND');
} else {
/* if file found */
res.on('data', data => writeFile(data, fileName));
res.on('end', data => EOF(data));
}
})
.on('error', function(res) {
console.log('error in reading URL');
});
});
}
getFile('master', 'bansalAyush', 'InstagramClone', '.babelrc', 'README.md');
其他回答
转到要下载的文件。单击它可查看GitHub UI中的内容。在右上角,右键单击“原始”按钮。另存为。。。
您可以复制GitHub文件的内容,然后将其粘贴到文件中。简单!
为了跟进thomasfuchs所说的,但对于GitHub Enterprise用户,您可以使用以下内容。
curl-H'授权:令牌INSERTACCESSTOKENHERE'-H'接受:application/vnd.github.v3.raw'-O-Lhttps://your_domain/api/v3/repos/owner/repo/contents/path
这里还有API文档https://developer.github.com/v3/repos/contents
根据这一要点,您可以使用wget或cURL:
单击GitHub repo中的文件名。单击“原始”以显示文件目录在浏览器中复制URL。在命令行中,运行以下任一命令:wget—无检查证书—内容处置https://URL-from-step3/卷曲-LJOhttps://URL-from-step3/再一个:在RHEL7.6中,运行以下命令:wget公司https://URL-from-step3/--输出文档=FILE_NAME
我最近发现了一个名为gitzip的服务,它也是开源的:
站点-http://kinolien.github.io/gitzip/
回购-https://github.com/KinoLien/gitzip
访问上述站点,输入repo或目录URL,您可以下载单个文件或整个目录作为zip文件。