MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / getWorkerFile

Method getWorkerFile

data/src/compression.js:26–109  ·  view source on GitHub ↗
(method)

Source from the content-addressed store, hash-verified

24 return this.decompressFile(compressed, data, updateMsg, fileCbFunc);
25 }
26 getWorkerFile(method) {
27 return new Promise(async (resolve, reject) => {
28 let path, obj;
29 if (method === "7z") {
30 path = "compression/extract7z.js";
31 obj = "sevenZip";
32 } else if (method === "zip") {
33 path = "compression/extractzip.js";
34 obj = "zip";
35 } else if (method === "rar") {
36 path = "compression/libunrar.js";
37 obj = "rar";
38 }
39 const res = await this.EJS.downloadFile(path, null, false, { responseType: "text", method: "GET" });
40 if (res === -1) {
41 this.EJS.startGameError(this.EJS.localization("Network Error"));
42 return;
43 }
44 if (method === "rar") {
45 const res2 = await this.EJS.downloadFile("compression/libunrar.wasm", null, false, { responseType: "arraybuffer", method: "GET" });
46 if (res2 === -1) {
47 this.EJS.startGameError(this.EJS.localization("Network Error"));
48 return;
49 }
50 const path = URL.createObjectURL(new Blob([res2.data], { type: "application/wasm" }));
51 let script = `
52 let dataToPass = [];
53 Module = {
54 monitorRunDependencies: function(left) {
55 if (left == 0) {
56 setTimeout(function() {
57 unrar(dataToPass, null);
58 }, 100);
59 }
60 },
61 onRuntimeInitialized: function() {},
62 locateFile: function(file) {
63 console.log("locateFile");
64 return "` + path + `";
65 }
66 };
67 ` + res.data + `
68 let unrar = function(data, password) {
69 let cb = function(fileName, fileSize, progress) {
70 postMessage({ "t": 4, "current": progress, "total": fileSize, "name": fileName });
71 };
72 let rarContent = readRARContent(data.map(function(d) {
73 return {
74 name: d.name,
75 content: new Uint8Array(d.content)
76 }
77 }), password, cb)
78 let rec = function(entry) {
79 if (!entry) return;
80 if (entry.type === "file") {
81 postMessage({ "t": 2, "file": entry.fullFileName, "size": entry.fileSize, "data": entry.fileContent });
82 } else if (entry.type === "dir") {
83 Object.keys(entry.ls).forEach(function(k) {

Callers 1

decompressFileMethod · 0.95

Calls 3

downloadFileMethod · 0.80
startGameErrorMethod · 0.80
localizationMethod · 0.80

Tested by

no test coverage detected