### Initialize GitZip and Fetch Repository URLs
Source: https://github.com/kinolien/gitzip/blob/master/example.html
This script initializes GitZip and fetches example repository URLs from the README.md file. It then creates buttons for each URL, allowing users to download the repository as a zip file.
```javascript
'use strict';
// call GitZip.zipRepo(url) with your url path to your github folder
// such as GitZip.zipRepo('https://github.com/kennethgoodman/gitzip/tree/gh-pages/js')
var exampleRx = /^\s*GitZip\.zipRepo\(\"([^\"]+)\"\);$/gm;
var createButtons = function (urls) {
urls.forEach(function (url) {
var button = document.createElement('button');
button.textContent = url;
button.addEventListener('click', function () {
GitZip.zipRepo(url);
});
document.body.appendChild(button);
document.body.appendChild(document.createElement('br'));
});
};
// fetches example URLs from the README
var req = new XMLHttpRequest();
req.open('GET', 'README.md');
req.overrideMimeType('text/plain');
req.onload = function (ev) {
var examples = [];
var match;
while (match = exampleRx.exec(this.responseText)) {
examples.push(match[1]);
}
createButtons(examples);
};
req.send();
```
--------------------------------
### Complete HTML Integration Example
Source: https://context7.com/kinolien/gitzip/llms.txt
A full HTML example demonstrating GitZip integration into a web page. It includes required dependencies, UI elements for URL input and status display, and event handling for the download button.
```html
GitZip Integration Example
```
--------------------------------
### Download Repository Content with GitZip
Source: https://context7.com/kinolien/gitzip/llms.txt
Use GitZip.zipRepo to download entire repositories, specific sub-directories, or single files. It handles different URL formats and branches. For root URLs, it redirects to GitHub's native download; otherwise, it fetches content via the API and creates a client-side ZIP. The optional second argument allows specifying a callback scope.
```javascript
// Download entire repository (redirects to GitHub's native ZIP download)
GitZip.zipRepo("https://github.com/KinoLien/gitzip");
```
```javascript
// Download a specific sub-directory as ZIP
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
```
```javascript
// Download from a specific branch
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/gh-pages/css");
```
```javascript
// Download a single file
GitZip.zipRepo("https://github.com/KinoLien/gitzip/blob/master/example.html");
```
```javascript
// With callback scope for progress tracking
var myApp = {
onProgress: function(status, message, percent) {
console.log(status + ": " + message);
}
};
GitZip.registerCallback(myApp.onProgress);
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js", myApp);
```
--------------------------------
### Register GitZip Progress Callback
Source: https://context7.com/kinolien/gitzip/llms.txt
Use GitZip.registerCallback to set a function that receives updates on the download process. This callback is invoked with status, message, and percentage, allowing for user feedback during operations like preparation, processing, completion, or errors.
```javascript
// Register a progress callback to track download status
GitZip.registerCallback(function(status, message, percent) {
// status: 'prepare' | 'processing' | 'done' | 'error'
// message: descriptive text about current operation
// percent: progress percentage (0-100, for debugging)
switch(status) {
case 'prepare':
console.log("Starting: " + message);
document.getElementById('status').textContent = "Preparing download...";
break;
case 'processing':
console.log("Processing: " + message);
document.getElementById('status').textContent = message;
break;
case 'done':
console.log("Complete: " + message);
document.getElementById('status').textContent = "Download complete!";
break;
case 'error':
console.error("Error: " + message);
document.getElementById('status').textContent = "Error: " + message;
break;
}
});
// Now zipRepo calls will trigger the callback
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
```
--------------------------------
### Download Single File with GitZip
Source: https://context7.com/kinolien/gitzip/llms.txt
Use GitZip.downloadFile to download a single file directly from a GitHub repository without zipping. The second argument can be a callback scope object, which will be available as `this` within the registered callback function.
```javascript
// Download a single file directly
GitZip.downloadFile("https://github.com/KinoLien/gitzip/blob/master/README.md");
```
```javascript
// With callback scope
var downloadScope = { name: "myDownload" };
GitZip.registerCallback(function(status, message) {
console.log(this.name + " - " + status + ": " + message);
});
GitZip.downloadFile(
"https://raw.githubusercontent.com/KinoLien/gitzip/master/LICENSE",
downloadScope
);
```
--------------------------------
### Zip Repository Root or Sub-directory
Source: https://github.com/kinolien/gitzip/blob/master/README.md
Use this function to create a zip archive of a GitHub repository. It accepts a URL pointing to the repository root, a specific sub-directory, or even a single file. The callbackScope parameter is optional and used to set the context for the progressCallback function.
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip");
```
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
```
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/");
```
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip/blob/master/example.html");
```
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/gh-pages/css");
```
--------------------------------
### Gitzip API - Register Callback
Source: https://github.com/kinolien/gitzip/blob/master/README.md
Register a callback function to receive progress updates during the zip creation process. The callback will be invoked with status, message, and percentage information.
```APIDOC
## GitZip.registerCallback
### Description
Registers a callback function to receive progress updates.
### Method
JavaScript Function
### Parameters
#### Path Parameters
- **inputFn** (function) - Required - The callback function to be called during different stages of the process (e.g., 'error', 'prepare', 'processing', 'done').
### Progress Callback Parameters
- **status** (string) - Indicates the status description (e.g., 'error', 'prepare', 'processing', 'done').
- **message** (string) - The messages associated with the current status.
- **percent** (number) - From 0 to 100, indicates the progress percentage.
### Request Example
```javascript
GitZip.registerCallback(function(status, message, percent) {
console.log(status, message, percent);
});
```
```
--------------------------------
### GitZip.downloadFile - Download Single File
Source: https://context7.com/kinolien/gitzip/llms.txt
Downloads a single file from a GitHub repository without zipping. This is useful when you only need one specific file rather than a directory.
```APIDOC
## GitZip.downloadFile
### Description
Downloads a single file from a GitHub repository without zipping. Useful when you only need one specific file rather than a directory.
### Method
`GitZip.downloadFile(url, scope)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
// Download a single file directly
GitZip.downloadFile("https://github.com/KinoLien/gitzip/blob/master/README.md");
// With callback scope
var downloadScope = { name: "myDownload" };
GitZip.registerCallback(function(status, message) {
console.log(this.name + " - " + status + ": " + message);
});
GitZip.downloadFile(
"https://raw.githubusercontent.com/KinoLien/gitzip/master/LICENSE",
downloadScope
);
```
### Response
#### Success Response (200)
This method does not return a value directly but initiates a file download. Progress and status updates are handled via registered callbacks.
#### Response Example
N/A (Initiates file download)
```
--------------------------------
### GitZip.registerCallback - Progress Callback
Source: https://context7.com/kinolien/gitzip/llms.txt
Registers a callback function to receive status updates during the ZIP creation process.
```APIDOC
## GitZip.registerCallback - Progress Callback
### Description
Registers a callback function to receive status updates during the ZIP creation process.
### Method
```javascript
GitZip.registerCallback(callbackFunction)
```
### Parameters
#### Path Parameters
- **callbackFunction** (function) - Required - The function to be called with status updates. It receives three arguments: `status` (string), `message` (string), and `percent` (number, optional).
### Request Example
```javascript
GitZip.registerCallback(function(status, message, percent) {
console.log(status + ": " + message);
if (percent !== undefined) {
console.log("Progress: " + percent + "%");
}
});
```
```
--------------------------------
### GitZip.registerCallback - Register Progress Callback
Source: https://context7.com/kinolien/gitzip/llms.txt
Registers a callback function that is invoked during various stages of the download process, including preparation, file fetching, compression, completion, and error states. This is essential for providing user feedback during potentially long-running operations.
```APIDOC
## GitZip.registerCallback
### Description
Registers a callback function that is invoked during various stages of the download process, including preparation, file fetching, compression, completion, and error states. Essential for providing user feedback during potentially long-running operations.
### Method
`GitZip.registerCallback(callbackFunction)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
// Register a progress callback to track download status
GitZip.registerCallback(function(status, message, percent) {
// status: 'prepare' | 'processing' | 'done' | 'error'
// message: descriptive text about current operation
// percent: progress percentage (0-100, for debugging)
switch(status) {
case 'prepare':
console.log("Starting: " + message);
document.getElementById('status').textContent = "Preparing download...";
break;
case 'processing':
console.log("Processing: " + message);
document.getElementById('status').textContent = message;
break;
case 'done':
console.log("Complete: " + message);
document.getElementById('status').textContent = "Download complete!";
break;
case 'error':
console.error("Error: " + message);
document.getElementById('status').textContent = "Error: " + message;
break;
}
});
// Now zipRepo calls will trigger the callback
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
```
### Response
#### Success Response (200)
This method does not return a value. It registers the provided callback function for future use.
#### Response Example
N/A
```
--------------------------------
### GitZip.zipFromApiUrl - ZIP from GitHub API URL
Source: https://context7.com/kinolien/gitzip/llms.txt
Creates a ZIP file from a GitHub API tree URL directly. This is a lower-level function useful when you already have the API URL from a previous GitHub API call.
```APIDOC
## GitZip.zipFromApiUrl - ZIP from GitHub API URL
### Description
Creates a ZIP file from a GitHub API tree URL directly. This is a lower-level function useful when you already have the API URL from a previous GitHub API call.
### Method
```javascript
GitZip.zipFromApiUrl(fileName, apiTreeUrl)
```
### Parameters
#### Path Parameters
- **fileName** (string) - Required - The desired name for the output ZIP file (without the .zip extension).
- **apiTreeUrl** (string) - Required - The GitHub API tree URL (e.g., obtained from GitHub API responses).
### Request Example
```javascript
// Use with a GitHub API tree URL (obtained from GitHub API responses)
var apiTreeUrl = "https://api.github.com/repos/KinoLien/gitzip/git/trees/master";
GitZip.registerCallback(function(status, message) {
console.log(status + ": " + message);
});
// Download and zip contents from the API URL
GitZip.zipFromApiUrl("my-download", apiTreeUrl);
// Creates: my-download.zip
```
```
--------------------------------
### Register Progress Callback
Source: https://github.com/kinolien/gitzip/blob/master/README.md
Register a callback function to receive updates on the zipping process. The callback will be invoked with status, message, and progress percentage information during file fetching, zipping, and error events.
```javascript
GitZip.registerCallback(inputFn);
```
--------------------------------
### Zip from GitHub API URL
Source: https://context7.com/kinolien/gitzip/llms.txt
Use this lower-level function when you already have the GitHub API tree URL from a previous call. It directly creates a ZIP file from the provided URL.
```javascript
// Use with a GitHub API tree URL (obtained from GitHub API responses)
var apiTreeUrl = "https://api.github.com/repos/KinoLien/gitzip/git/trees/master";
GitZip.registerCallback(function(status, message) {
console.log(status + ": " + message);
});
// Download and zip contents from the API URL
GitZip.zipFromApiUrl("my-download", apiTreeUrl);
// Creates: my-download.zip
```
--------------------------------
### GitZip.zipRepo - Download Repository Content as ZIP
Source: https://context7.com/kinolien/gitzip/llms.txt
Downloads a GitHub repository, sub-directory, or single file as a ZIP archive. It automatically detects the URL type and handles branch resolution. For root URLs, it redirects to GitHub's native archive download; for sub-directories and files, it fetches content via the GitHub API and creates a client-side ZIP.
```APIDOC
## GitZip.zipRepo
### Description
Downloads a GitHub repository, sub-directory, or single file as a ZIP archive. Automatically detects the URL type and handles branch resolution, including complex branch names with slashes. For root URLs, redirects to GitHub's native archive download; for sub-directories and files, fetches content via the GitHub API and creates a client-side ZIP.
### Method
`GitZip.zipRepo(url, scope)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
// Download entire repository (redirects to GitHub's native ZIP download)
GitZip.zipRepo("https://github.com/KinoLien/gitzip");
// Download a specific sub-directory as ZIP
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
// Download from a specific branch
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/gh-pages/css");
// Download a single file
GitZip.zipRepo("https://github.com/KinoLien/gitzip/blob/master/example.html");
// With callback scope for progress tracking
var myApp = {
onProgress: function(status, message, percent) {
console.log(status + ": " + message);
}
};
GitZip.registerCallback(myApp.onProgress);
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js", myApp);
```
### Response
#### Success Response (200)
This method does not return a value directly but initiates a file download. Progress and status updates are handled via registered callbacks.
#### Response Example
N/A (Initiates file download)
```
--------------------------------
### Gitzip API - Zip Repository
Source: https://github.com/kinolien/gitzip/blob/master/README.md
This function allows you to create a zip archive of a GitHub repository or a specific sub-directory within it. You can provide a URL to the repository root, a sub-directory, or even a specific file.
```APIDOC
## GitZip.zipRepo
### Description
Creates a zip archive from a GitHub repository or a sub-directory.
### Method
JavaScript Function
### Parameters
#### Path Parameters
- **pathToFolder** (string) - Required - The URL of the Github repository or sub-directory.
- **callbackScope** (object) - Optional - The scope of the progressCallback function. If you have registered a callback, the code will execute like this: `yourcallback.apply(callbackScope, arguments)`
### Request Example
```javascript
GitZip.zipRepo("https://github.com/KinoLien/gitzip");
GitZip.zipRepo("https://github.com/KinoLien/gitzip/tree/master/js");
GitZip.zipRepo("https://github.com/KinoLien/gitzip/blob/master/example.html");
```
```
--------------------------------
### Set GitHub API Access Token
Source: https://context7.com/kinolien/gitzip/llms.txt
Call GitZip.setAccessToken with a GitHub personal access token to increase API rate limits. This is crucial for downloading large directories or performing frequent requests. The token can be cleared by setting an empty string or null.
```javascript
// Set access token before making requests
// Generate token at: https://github.com/settings/tokens
// Required scope: public_repo (for public repositories)
GitZip.setAccessToken("ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// Now requests will be authenticated with higher rate limits
GitZip.zipRepo("https://github.com/facebook/react/tree/main/packages");
// Clear token by setting empty string or null
GitZip.setAccessToken("");
```
--------------------------------
### URL Resolution Utility
Source: https://context7.com/kinolien/gitzip/llms.txt
GitZip's internal URL resolver parses and validates GitHub URLs, including complex branch names with slashes, by making API calls to verify the correct branch/path combination. It works for both tree and blob URLs.
```javascript
// Resolve a GitHub URL to its components
GitZip.urlResolver.check("https://github.com/Microsoft/CNTK/tree/release/2.1/Examples")
.then(function(resolved) {
console.log("Author:", resolved.author); // "Microsoft"
console.log("Project:", resolved.project); // "CNTK"
console.log("Branch:", resolved.branch); // "release/2.1"
console.log("Path:", resolved.path); // "Examples"
console.log("Type:", resolved.type); // "tree"
console.log("Root URL:", resolved.rootUrl); // Full root URL
console.log("Input URL:", resolved.inputUrl); // Original input
})
.catch(function(error) {
console.error("Invalid GitHub URL");
});
// Works with blob URLs too
GitZip.urlResolver.check("https://github.com/KinoLien/gitzip/blob/master/README.md")
.then(function(resolved) {
console.log(resolved.type); // "blob"
console.log(resolved.path); // "README.md"
});
```
--------------------------------
### GitZip.urlResolver - URL Resolution Utility
Source: https://context7.com/kinolien/gitzip/llms.txt
Internal URL resolver that can be used to parse and validate GitHub URLs. Resolves complex branch names (including those with slashes) by making API calls to verify the correct branch/path combination.
```APIDOC
## GitZip.urlResolver - URL Resolution Utility
### Description
Internal URL resolver that can be used to parse and validate GitHub URLs. Resolves complex branch names (including those with slashes) by making API calls to verify the correct branch/path combination.
### Method
```javascript
GitZip.urlResolver.check(githubUrl)
```
### Parameters
#### Path Parameters
- **githubUrl** (string) - Required - The GitHub URL to resolve.
### Response
#### Success Response (Promise resolves with an object containing)
- **author** (string) - The repository author.
- **project** (string) - The repository name.
- **branch** (string) - The resolved branch name.
- **path** (string) - The resolved path within the repository.
- **type** (string) - The type of URL ('tree' or 'blob').
- **rootUrl** (string) - The full root URL of the repository.
- **inputUrl** (string) - The original input URL.
### Request Example
```javascript
// Resolve a GitHub URL to its components
GitZip.urlResolver.check("https://github.com/Microsoft/CNTK/tree/release/2.1/Examples")
.then(function(resolved) {
console.log("Author:", resolved.author); // "Microsoft"
console.log("Project:", resolved.project); // "CNTK"
console.log("Branch:", resolved.branch); // "release/2.1"
console.log("Path:", resolved.path); // "Examples"
console.log("Type:", resolved.type); // "tree"
console.log("Root URL:", resolved.rootUrl); // Full root URL
console.log("Input URL:", resolved.inputUrl); // Original input
})
.catch(function(error) {
console.error("Invalid GitHub URL");
});
// Works with blob URLs too
GitZip.urlResolver.check("https://github.com/KinoLien/gitzip/blob/master/README.md")
.then(function(resolved) {
console.log(resolved.type); // "blob"
console.log(resolved.path); // "README.md"
});
```
```
--------------------------------
### GitZip.zipRepo - ZIP Repository
Source: https://context7.com/kinolien/gitzip/llms.txt
Initiates the process of downloading and zipping a GitHub repository or a specific part of it based on a provided URL.
```APIDOC
## GitZip.zipRepo - ZIP Repository
### Description
Initiates the process of downloading and zipping a GitHub repository or a specific part of it based on a provided URL.
### Method
```javascript
GitZip.zipRepo(githubUrl)
```
### Parameters
#### Path Parameters
- **githubUrl** (string) - Required - A valid GitHub URL pointing to a repository, a specific branch, or a folder/file within a repository.
### Request Example
```javascript
// Handle download button click
document.getElementById('downloadBtn').addEventListener('click', function() {
var url = document.getElementById('repoUrl').value.trim();
if (url) {
try {
GitZip.zipRepo(url);
} catch (e) {
document.getElementById('status').textContent = "Error: " + e;
}
} else {
alert("Please enter a GitHub URL");
}
});
```
```
--------------------------------
### GitZip.setAccessToken - Set GitHub API Access Token
Source: https://context7.com/kinolien/gitzip/llms.txt
Sets a GitHub personal access token to increase API rate limits from 60 requests/hour (unauthenticated) to 5,000 requests/hour (authenticated). This is required for downloading large directories or making frequent requests.
```APIDOC
## GitZip.setAccessToken
### Description
Sets a GitHub personal access token to increase API rate limits from 60 requests/hour (unauthenticated) to 5,000 requests/hour (authenticated). Required for downloading large directories or making frequent requests.
### Method
`GitZip.setAccessToken(token)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
// Set access token before making requests
// Generate token at: https://github.com/settings/tokens
// Required scope: public_repo (for public repositories)
GitZip.setAccessToken("ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// Now requests will be authenticated with higher rate limits
GitZip.zipRepo("https://github.com/facebook/react/tree/main/packages");
// Clear token by setting empty string or null
GitZip.setAccessToken("");
```
### Response
#### Success Response (200)
This method does not return a value. It sets the access token for subsequent API requests.
#### Response Example
N/A
```
--------------------------------
### GitZip.setAccessToken - GitHub Access Token
Source: https://context7.com/kinolien/gitzip/llms.txt
Sets a GitHub Personal Access Token to be used for API requests, which can increase rate limits.
```APIDOC
## GitZip.setAccessToken - GitHub Access Token
### Description
Sets a GitHub Personal Access Token to be used for API requests, which can increase rate limits.
### Method
```javascript
GitZip.setAccessToken(token)
```
### Parameters
#### Path Parameters
- **token** (string) - Required - Your GitHub Personal Access Token.
### Request Example
```javascript
// Optional: Set access token for higher rate limits
GitZip.setAccessToken("your_github_token_here");
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.