forked from gn-math/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.js
More file actions
36 lines (33 loc) · 1.25 KB
/
merge.js
File metadata and controls
36 lines (33 loc) · 1.25 KB
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
window.universallength = 0;
window.universalloaded = 0;
window.mergeFiles = function(fileParts) {
return new Promise((resolve, reject) => {
let buffers = [];
function fetchPart(index) {
if (index >= fileParts.length) {
let mergedBlob = new Blob(buffers);
let mergedFileUrl = URL.createObjectURL(mergedBlob);
resolve(mergedFileUrl);
return;
}
fetch(fileParts[index]).then((response) => {
if (!response.ok) throw new Error("Missing part: " + fileParts[index]);
return response.arrayBuffer();
}).then((data) => {
window.universalloaded++;
document.getElementById("loading-text").textContent = "LOADING... "+window.universalloaded+"/"+window.universallength;
buffers.push(data);
fetchPart(index + 1);
}).catch(reject);
}
fetchPart(0);
});
};
window.getParts = function(file, start, end) {
let parts = [];
for (let i = start; i <= end; i++) {
parts.push(file + ".part" + i);
}
window.universallength = window.universallength+parts.length;
return parts;
};