A more comprehensive tool is available at
ext-code.com : download a directory from a github repository
A thorough description of the code is given below
you can download a zipped directory right here in the browser by running the following code snippet
The path can be empty ( therefore it will download all files in the repo )
As per the documentation
docs.github.com : REST API endpoints for Git trees : Get a tree
a complete list of files for a repo can be downloaded in json format by adding ?recursive=true
to the endpoint
https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=true
each file can be downloaded individually from
raw.githubusercontent.com
https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${path}
and the whole process only requires 1 github api request which helps with the github api rate restrictions,
60 p/hr anonymous, 5000 p/hr authorised, there is however a delay between updating a repo and those changes
being reflected at raw.githubusercontent.com, this can be 5-10mins
Individual files can also be downloaded from ( changes reflected immediately )
https://api.github.com/repos/${owner}/${repo}/contents/${path}
To use authorized requests with the github api, a http header needs to be added to the request
authorization : bearer ${token}
A GitHub api token can be generated at
github.com : Fine-grained personal access tokens
you'll need to add
permissions / repository permissions / contents
permission to the token
Given a successful request the api url will return a json object with the file data base64 encoded in the content field, such as
This structure can then be coupled with npm : jszip to create a zip file containing the files in the folder
For those wishing to do all this in nodejs, the following will write directly to disk
To get jszip working in nodejs this seems to work
There is also the node --experimental-network-imports flag node.js : HTTPS and HTTP imports
//test.node.mjs
import JSZip from 'https://cdn.jsdelivr.net/npm/jszip/+esm';
console.log(JSZip);
and then run with
node --experimental-network-imports --no-warnings .\test.node.mjs