如何使用nodejs在git repo中下载文件?

时间:2023-02-06 00:29:00

I want to download a file in git repo without clone it.
For example lodash git repo :

我想在没有克隆的情况下下载git repo中的文件。例如lodash git repo:

https://github.com/lodash/lodash/

in that git there is file lodash.js:

在那个git中有文件lodash.js:

https://github.com/lodash/lodash/blob/master/lodash.js

I have try using nodegit but still need to clone all files first.

我尝试使用nodegit但仍需要先克隆所有文件。

How to download lodash.js file only in git repo using nodejs?

如何使用nodejs仅在git repo中下载lodash.js文件?

2 个解决方案

#1


2  

It is easy enough to curl a single file from a git repo

从git repo卷曲单个文件很容易

curl -L -O github.com/user/repository/raw/branch/filename

Since you have nodejs, you can use chriso/curlrequest, a node wrapper for curl.

既然你有nodejs,你可以使用chriso / curlrequest,一个curl的节点包装器。

npm install curlrequest
raw.githubusercontent.com/lodash/lodash/master/lodash.js 
curl.request({ url: 'https://raw.githubusercontent.com/lodash/lodash/master/lodash.js' }, function (err, stdout, meta) {
    console.log('%s %s', meta.cmd, meta.args.join(' '));
});

#2


0  

You could use download the zip using the direct URL (https://github.com/lodash/lodash/archive/master.zip) and use adm-zip (https://github.com/cthackers/adm-zip) to unzip it locally.

您可以使用直接URL(https://github.com/lodash/lodash/archive/master.zip)下载zip并使用adm-zip(https://github.com/cthackers/adm-zip)在本地解压缩。

#1


2  

It is easy enough to curl a single file from a git repo

从git repo卷曲单个文件很容易

curl -L -O github.com/user/repository/raw/branch/filename

Since you have nodejs, you can use chriso/curlrequest, a node wrapper for curl.

既然你有nodejs,你可以使用chriso / curlrequest,一个curl的节点包装器。

npm install curlrequest
raw.githubusercontent.com/lodash/lodash/master/lodash.js 
curl.request({ url: 'https://raw.githubusercontent.com/lodash/lodash/master/lodash.js' }, function (err, stdout, meta) {
    console.log('%s %s', meta.cmd, meta.args.join(' '));
});

#2


0  

You could use download the zip using the direct URL (https://github.com/lodash/lodash/archive/master.zip) and use adm-zip (https://github.com/cthackers/adm-zip) to unzip it locally.

您可以使用直接URL(https://github.com/lodash/lodash/archive/master.zip)下载zip并使用adm-zip(https://github.com/cthackers/adm-zip)在本地解压缩。