-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
81 lines (59 loc) · 1.77 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
<!doctype html>
<html>
<input type="file" id="file-input" />
<br>
<br>
<a id='a' download='Fixfix.gzr' type='application/octet-stream'>Download fixed replay</a>
<pre id="output"></pre>
<script src="fgrc.js"></script>
<script>
function insertBeforeLastOccurrence(strToSearch, strToFind, strToInsert) {
var n = strToSearch.lastIndexOf(strToFind);
if (n < 0) return strToSearch;
return strToSearch.substring(0,n) + strToInsert + strToSearch.substring(n);
}
function readSingleFile(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var a = document.getElementById('a');
a.download = insertBeforeLastOccurrence(file.name, ".gzr", "_repaired");
var reader = new FileReader();
reader.onloadstart = function(e) {
var output = document.getElementById('output');
output.innerHTML = 'Loading...<br>';
};
function loadFile(e) {
var contents = e.target.result;
var vector = new Module.FileVector;
var arr = new Uint8Array(contents);
console.log('Length: ' + arr.length);
for (i = 0; i < arr.length; i++)
{
vector.push_back(arr[i]);
}
console.log('Length: ' + arr.length + ', ' + vector.size());
var ret = Module.RepairFile(vector);
var arr = new Uint8Array(ret.size());
console.log('Uint8Array length: ' + arr.length);
for (i = 0; i < arr.length; i++)
{
arr[i] = ret.get(i);
}
var blob = new Blob([arr], {type: 'application/octet-binary'});
var a = document.getElementById('a');
a.href = URL.createObjectURL(blob);
//blob = null;
arr = null;
vector = null;
};
reader.onload = function (e) {
setTimeout(loadFile, 0, e);
}
reader.readAsArrayBuffer(file);
}
document.getElementById('file-input')
.addEventListener('change', readSingleFile, false);
</script>
</html>