mirror of
https://github.com/schibo/1964js.git
synced 2025-04-02 10:52:54 -04:00
git-svn-id: http://1964js.googlecode.com/svn/trunk@108 0378edba-076e-5dc0-2bb2-d87a714dcd81
79 lines
No EOL
2.6 KiB
HTML
79 lines
No EOL
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html><head>
|
|
<script src="io.js"></script>
|
|
<script src="archive.js"></script>
|
|
</head>
|
|
<body>
|
|
<input id='filechooser' type='file'></input>
|
|
</body>
|
|
<script>
|
|
|
|
function assertTrue(a) {
|
|
if (!a) {
|
|
alert("'" + a + "' not true");
|
|
}
|
|
}
|
|
function assertEquals(a,b) {
|
|
if (a != b) {
|
|
alert("'" + a + "' != '" + b + "'")
|
|
}
|
|
}
|
|
|
|
function testAddRemoveEventListeners() {
|
|
var progress = function(e) { alert('progress') };
|
|
var progress2 = function(e) { alert('progress2') };
|
|
|
|
var ua = new bitjs.archive.Unarchiver(null);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress2);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress2);
|
|
assertEquals(2, ua.listeners_[bitjs.archive.UnarchiveEvent.Type.PROGRESS].length);
|
|
|
|
ua.removeEventListener(bitjs.archive.UnarchiveEvent.Type.START, progress);
|
|
assertEquals(2, ua.listeners_[bitjs.archive.UnarchiveEvent.Type.PROGRESS].length);
|
|
|
|
ua.removeEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, progress);
|
|
assertEquals(1, ua.listeners_[bitjs.archive.UnarchiveEvent.Type.PROGRESS].length);
|
|
}
|
|
|
|
function testAbstractUnarchiveThrows() {
|
|
var ua = new bitjs.archive.Unarchiver(null);
|
|
try {
|
|
ua.start();
|
|
alert("unarchive() didn't throw");
|
|
} catch(e) {}
|
|
}
|
|
|
|
// unit tests
|
|
// testAddRemoveEventListeners();
|
|
// testAbstractUnarchiveThrows();
|
|
// var uz = new bitjs.archive.Unzipper(null);
|
|
|
|
document.body.querySelector("#filechooser").addEventListener("change",
|
|
function(evt) {
|
|
var inp = evt.target;
|
|
var filelist = inp.files;
|
|
if (filelist.length == 1) {
|
|
var blob = filelist[0];
|
|
var fr = new FileReader();
|
|
fr.onload = function() {
|
|
var ua = new bitjs.archive.Unzipper(fr.result);
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.INFO, function(e) {
|
|
console.log("info: " + e.msg);
|
|
})
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, function(e) {
|
|
console.log("progress: " + e.msg);
|
|
})
|
|
ua.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT, function(e) {
|
|
console.log("extract: " + e.unarchiveFile.filename);
|
|
})
|
|
ua.start();
|
|
};
|
|
fr.readAsArrayBuffer(blob);
|
|
}
|
|
}, false);
|
|
|
|
</script>
|
|
</html> |