-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
391 lines (348 loc) · 12.6 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="Unarchiver.js" />
<meta name="author" content="Xenova" />
<title>Unarchiver.js</title>
<!-- Favicon-->
<!-- Icon made by Webalys (https://www.flaticon.com/authors/webalys) -->
<link rel="icon" type="image/x-icon" href="assets/icons/favicon.ico" />
<!-- Bootstrap icons-->
<link href="assets/css/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="assets/css/theme.css" rel="stylesheet" />
<!-- Code highlighting -->
<link href="assets/css/prism.css" rel="stylesheet" />
<!-- Custom styles for page -->
<link href="assets/css/style.css" rel="stylesheet" />
</head>
<body>
<!-- Responsive navbar-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container px-5">
<a class="navbar-brand" href="#">Unarchiver.js</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link" href="#getting-started">Getting Started</a></li>
<li class="nav-item"><a class="nav-link" href="#demo">Demo</a></li>
<li class="nav-item"><a class="nav-link" href="#usage">Usage</a></li>
<li class="nav-item"><a class="nav-link" href="#examples">Examples</a></li>
</ul>
</div>
</div>
</nav>
<!-- Modal -->
<div class="modal fade" id="content-modal" tabindex="-1" aria-labelledby="modal-label" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-label">Viewing content</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body"></div>
</div>
</div>
</div>
<!-- Header-->
<header class="bg-dark pt-3 pb-5">
<div class="container px-5">
<div class="row gx-5 justify-content-center">
<div class="col-lg-6">
<div class="text-center">
<h1 class="display-5 fw-bolder text-white mb-2">Unarchiver.js</h1>
<p class="lead text-white-50 mb-4">The simple, all-in-one, JavaScript unarchiver that runs in
your browser!</p>
<div class="d-grid gap-3 d-sm-flex justify-content-sm-center">
<a class="btn btn-primary btn-lg px-4 me-sm-3" href="build/unarchiver.zip">Download</a>
<a class="btn btn-outline-light btn-lg px-4" href="https://github.com/xenova/unarchiver.js">
<i class="bi bi-github"></i> View Source
</a>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- Getting started section -->
<section class="py-4 border-bottom" id="getting-started">
<div class="container px-5 my-3">
<div class="mb-3">
<h2 class="fw-bolder">Getting Started</h2>
</div>
<div class="row gx-5">
<div class="col-lg-6 mb-4 mb-lg-0">
<p class="lead mb-0">Include source on page (HTML)</p>
<pre><code class="language-html"><!-- Local (remember to extract all files) -->
<script src="./unarchiver.min.js"></script>
<!-- or Remote -->
<script src="https://xenova.github.io/unarchiver.js/dist/unarchiver.min.js"></script></code></pre>
</div>
<div class="col-lg-6 mb-4 mb-lg-0">
<p class="lead mb-0">Usage (JavaScript)</p>
<pre><code class="language-js">// Load file (e.g., from URL or input element)
let file = new File(...);
// Open the file archive for reading
Unarchiver.open(file).then(async function (archive) {
for (let entry of archive.entries) {
if (entry.is_file) {
// File object for archive entry
let entry_file = await entry.read();
}
}
});</code></pre>
</div>
</div>
</div>
</section>
<!-- Demo section-->
<section class="py-4 border-bottom" id="demo">
<div class="container px-5 my-4">
<div class="mb-4">
<h2 class="fw-bolder">Demo</h2>
<p class="lead mb-0">Add archives by dragging files onto the dropzone or selecting them manually.</p>
</div>
<div class="row gx-5">
<div class="col-lg-6 mb-4 mb-lg-0">
<div id="dropzone" class="card">
<label for="file">
<span>
<label>Add Files</label>
<i class="bi bi-file-earmark-plus"></i>
</span>
<input id="file" type="file" multiple>
</label>
</div>
</div>
<div class="col-lg-6">
<div id="display-files" class="overflow-auto card p-2"></div>
</div>
<div class="col-lg-12 d-flex justify-content-end mt-2">
<button class="btn btn-primary"
onclick="document.getElementById('display-files').innerHTML=''">Reset</button>
</div>
</div>
</div>
</section>
<!-- Usage section-->
<section class="py-4 border-bottom" id="usage">
<div class="container px-5 my-4">
<div class="mb-3">
<h2 class="fw-bolder">Usage</h2>
</div>
<div class="row gx-5 justify-content-center">
<div class="col-lg-12 mb-3">
<h4 class="fw-bolder">Methods</h4>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Example</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>Unarchiver.load(formats=null)</code></th>
<td>Returns a <a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
class="link-primary">Promise</a> which will be fulfilled when the specified
formats have been loaded. <code>format</code> is an array of formats to be loaded,
selected from: <code>zip</code>, <code>rar</code>, <code>tar</code>,
<code>gz</code>, <code>xz</code>, and <code>bz2</code>. If no formats are provided,
all supported formats will be loaded.
<br><br>
Note: calling this method is optional since, by default, formats are loaded when
they are needed for the first time. This method is used to speed up processing by
preloading the necessary files.
</td>
<td>
<pre><code class="language-js small-code">// Load all supported formats
Unarchiver.load().then(function() {
console.log('Finished loading all formats');
});
// Load certain formats
Unarchiver.load(['zip', 'tar']).then(function() {
console.log('Finished loading certain formats');
});
</code></pre>
</td>
</tr>
<tr>
<th scope="row"><code>Unarchiver.open(file)</code></th>
<td>Returns a <a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
class="link-primary">Promise</a> which will be fulfilled when the file has been
opened/unarchived. The fulfilled Promise contains the readable archive and holds the
following information:<br>
<pre>{
"file_name": String,
"archive_type": String,
"array_buffer": ArrayBuffer,
"entries": [object]
}</pre>
See below for how to read the archive entries.
</td>
<td>
<pre><code class="language-js small-code">// See below for examples on how to read files
let file = new File(...);
Unarchiver.open(file).then(function(archive) {
console.log(archive.file_name);
console.log(archive.archive_type);
console.log(archive.entries);
});
</code></pre>
</td>
</tr>
<tr>
<th scope="row"><code>Unarchiver.close(archive)</code></th>
<td>Close an opened archive. Usually, this method is unnecessary, but may be useful if
you wish to save memory.</td>
<td>
<pre><code class="language-js small-code">Unarchiver.open(file).then(function(archive) {
// Close archive
Unarchiver.close(archive);
});
</code></pre>
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-12">
<h4 class="fw-bolder">Archive Entries</h4>
Each achive entry object contains the following attributes:
<pre>{
"name": String,
"is_file": Boolean,
"size_compressed": Integer,
"size_uncompressed": Integer
}</pre>
Additionally, an archive entry object contains a <code>read()</code> method which is used to read
its data.
This method returns a <a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
class="link-primary">Promise</a> which will be fulfilled when the file has been loaded. The
fulfilled Promise contains the File object of the entry. This means that regular File operations can
be used to extract its data. For example:
<pre><code class="language-js">Unarchiver.open(file).then(async function (archive) {
// Archive metadata
let archive_name = archive.file_name;
let archive_type = archive.archive_type;
for (let entry of archive.entries) {
// Entry's metadata
let name = entry.name;
let is_file = entry.is_file;
let size_compressed = entry.size_compressed;
let size_uncompressed = entry.size_uncompressed;
// Entry's data
if (is_file) {
// File object for archive entry
let entry_file = await entry.read();
// Actual data for archive entry
let entry_file_data = await entry_file.arrayBuffer();
// ... do something with entry_file and entry_file_data
console.log(entry_file, entry_file_data);
}
}
});
</code></pre>
</div>
</div>
</div>
</section>
<!-- Examples section-->
<section class="py-4 border-bottom" id="examples">
<div class="container px-5 my-4">
<div class="mb-4">
<h2 class="fw-bolder">Examples</h2>
</div>
<div class="row gx-5">
<div class="col-lg-12 mb-3">
<h4 class="fw-bolder">Read remote archive (from URL)</h4>
<pre><code class="language-js">let url = 'https://xenova.github.io/unarchiver.js/test_files/file.zip';
fetch(url).then(async function (data) {
// Load file from URL
let blob = await data.blob();
let file = new File([blob], url.split('/').pop(), { type: blob.type });
// Open the file archive
let archive = await Unarchiver.open(file);
for (let entry of archive.entries) {
if (entry.is_file) {
// File object for archive entry
let entry_file = await entry.read();
console.log(entry_file); // do something
}
}
});</code></pre>
</div>
<h4 class="fw-bolder">Read local archive (from input element)</h4>
<div class="col-lg-6 mb-3">
<pre><code class="language-html"><input type="file" id="example-file">
<button onclick="readFile()">Read</button><br>
<div id="example-output"></div>
<script>
function readFile() {
let file = document.getElementById('example-file').files[0]
if (!file) return;
let output = document.getElementById('example-output');
// Open the file archive for reading
Unarchiver.open(file).then(async function (archive) {
output.innerHTML = '';
for (let entry of archive.entries) {
if (entry.is_file) {
output.innerHTML += entry.name + '<br>';
// File object for archive entry
// let entry_file = await entry.read();
}
}
});
}
</script></code></pre>
</div>
<div class="col-lg-6">
<input type="file" id="example-file"> <button onclick="readFile()">Read</button>
<br>
<div id="example-output"></div>
<script>
function readFile() {
let file = document.getElementById('example-file').files[0]
if (!file) return;
let output = document.getElementById('example-output');
// Open the file archive for reading
Unarchiver.open(file).then(async function (archive) {
output.innerHTML = '';
for (let entry of archive.entries) {
if (entry.is_file) {
output.innerHTML += entry.name + '<br>';
// File object for archive entry
// let entry_file = await entry.read();
}
}
});
}
</script>
</div>
</div>
</div>
</section>
<!-- Footer-->
<footer class="py-3 bg-dark">
<div class="container px-5">
<p class="m-0 text-center text-white">Copyright © Xenova 2021</p>
</div>
</footer>
<!-- Bootstrap core JS-->
<script src="assets/js/bootstrap.bundle.min.js"></script>
<!-- Code highlighting JS -->
<script src="assets/js/prism.js"></script>
<!-- Unarchiver -->
<script src="dist/unarchiver.min.js"></script>
<!-- Page JS-->
<script src="assets/js/scripts.js"></script>
</body>
</html>