从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');

其他回答

I.如果您想下载.so之类的文件而不是源代码,请尝试单击下面的下载按钮:

该文件将从您的浏览器下载。

二、如果您想下载源代码,请单击“原始”,然后转到“原始”。。页

简单地复制/粘贴或使用curl或wget命令在终端中获取它。

GitHub Mate可以轻松下载单个文件,只需单击图标即可下载,目前它只能在Chrome上运行。

只需将wget与raw=True参数一起使用

wget "https://github.com/user/repository/blob/master/directory/file_name?raw=True" -O target_path/file_name

我最近发现了一个名为gitzip的服务,它也是开源的:

站点-http://kinolien.github.io/gitzip/

回购-https://github.com/KinoLien/gitzip

访问上述站点,输入repo或目录URL,您可以下载单个文件或整个目录作为zip文件。

转到DownGit-输入您的URL-只需下载

无需安装任何东西或遵循复杂的说明;特别适用于大型源文件。



您可以下载单独的文件和目录作为zip文件,也可以创建下载链接。

免责声明:我是此工具的作者。