mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
Rename unzipper test harness files.
This commit is contained in:
parent
755aba54bd
commit
adc2f698ae
2 changed files with 58 additions and 0 deletions
14
tests/unzipper-test.html
Normal file
14
tests/unzipper-test.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Tiny web inteface to test performance of the Unzipper.</title>
|
||||||
|
<script src="zipper-test.js" type="module"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<input id="zip-tester" type="file" multiple>
|
||||||
|
<span id="archive-uploader-label">Select a bunch of zip files</span>
|
||||||
|
</div>
|
||||||
|
<div id="result"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
44
tests/unzipper-test.js
Normal file
44
tests/unzipper-test.js
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
import { UnarchiveEventType, Unzipper } from '../archive/archive.js';
|
||||||
|
|
||||||
|
const result = document.querySelector('#result');
|
||||||
|
const fileInputEl = document.querySelector('#zip-tester');
|
||||||
|
|
||||||
|
async function getFiles(fileChangeEvt) {
|
||||||
|
result.innerHTML = `Starting to load files`;
|
||||||
|
const files = fileChangeEvt.target.files;
|
||||||
|
const buffers = [];
|
||||||
|
for (const file of files) {
|
||||||
|
buffers.push(await new Promise((resolve, reject) => {
|
||||||
|
const fr = new FileReader();
|
||||||
|
fr.onload = () => {
|
||||||
|
resolve(new Uint8Array(fr.result));
|
||||||
|
};
|
||||||
|
fr.readAsArrayBuffer(file);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.innerHTML = `Loaded files`;
|
||||||
|
|
||||||
|
let fileNum = 0;
|
||||||
|
const INC = 100 / files.length;
|
||||||
|
const start = performance.now();
|
||||||
|
|
||||||
|
for (const b of buffers) {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const unzipper = new Unzipper(b.buffer, { pathToBitJS: '../' });
|
||||||
|
unzipper.addEventListener(UnarchiveEventType.FINISH, () => {
|
||||||
|
fileNum++;
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
result.innerHTML = `Unzipping file ${fileNum} / ${files.length}`;
|
||||||
|
unzipper.start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const end = performance.now();
|
||||||
|
result.innerHTML = `Unzipping took ${end - start}ms`;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileInputEl.addEventListener('change', getFiles, false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue