-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathzip-wheel-explorer.html
87 lines (83 loc) · 2.89 KB
/
zip-wheel-explorer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<title>Package File Browser</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
body {
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
margin: 2rem;
max-width: 800px;
margin: 0 auto;
}
input, textarea {
font-size: 16px;
width: 100%;
margin-bottom: 1rem;
padding: 0.5rem;
box-sizing: border-box;
}
#fileList, #fileContent {
border: 1px solid #ddd;
padding: 1rem;
margin-top: 1rem;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
background-color: #f4f4f4;
padding: 1rem;
max-height: 400px;
overflow-y: auto;
}
</style>
</head>
<body>
<h1>Package File Browser</h1>
<input type="text" id="urlInput" placeholder="Paste URL to .zip, .tar.gz, or .whl file">
<button onclick="fetchAndUnpackFile()">Unpack File</button>
<p>Try a wheel from PyPI like: <code>https://files.pythonhosted.org/packages/ae/8f/e0661dd3077b7343419ddb5ff840f6bcf571e8d11d8acb031e1b167de79c/llm_mistral-0.8-py3-none-any.whl</code> (<a href="#" onclick="document.getElementById('urlInput').value='https://files.pythonhosted.org/packages/ae/8f/e0661dd3077b7343419ddb5ff840f6bcf571e8d11d8acb031e1b167de79c/llm_mistral-0.8-py3-none-any.whl'; fetchAndUnpackFile(); return false">try it</a>)</p>
<div id="fileList" style="display: none"></div>
<div id="fileContent" style="display: none"></div>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
<script>
async function fetchAndUnpackFile() {
const url = document.getElementById('urlInput').value;
const fileListEl = document.getElementById('fileList');
const fileContentEl = document.getElementById('fileContent');
fileListEl.innerHTML = 'Downloading file...';
fileContentEl.innerHTML = '';
try {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const files = await extractFiles(arrayBuffer, url);
fileListEl.style.display = 'block';
fileListEl.innerHTML = '<h3>Files in package:</h3>';
files.forEach((file, index) => {
const fileEl = document.createElement('div');
fileEl.textContent = file.name;
fileEl.style.cursor = 'pointer';
fileEl.onclick = () => {
fileContentEl.style.display = 'block';
fileContentEl.innerHTML = `<h3>${file.name}</h3><pre>${file.content}</pre>`;
};
fileListEl.appendChild(fileEl);
});
} catch (error) {
fileListEl.innerHTML = `Error: ${error.message}`;
console.error(error);
}
}
async function extractFiles(arrayBuffer, url) {
const files = [];
const zip = await JSZip.loadAsync(arrayBuffer);
for (const [name, file] of Object.entries(zip.files)) {
const content = await file.async('text');
files.push({ name, content });
}
return files;
}
</script>
</body>
</html>