blob: 513ccd4bbc111f3996c5cabdf87e8f918b61e862 [file] [log] [blame]
swissChiliab615d82024-03-08 17:15:13 -05001var createMyModule = (() => {
2 var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
3 if (typeof __filename !== 'undefined') _scriptDir ||= __filename;
4 return (
5 function(moduleArg = {}) {
6 function require(name) {}
7
8 var Module = moduleArg;
9 var readyPromiseResolve, readyPromiseReject;
10 Module["ready"] = new Promise((resolve, reject) => {
11 readyPromiseResolve = resolve;
12 readyPromiseReject = reject
13 });
14 if (!Module.expectedDataFileDownloads) {
15 Module.expectedDataFileDownloads = 0
16 }
17 Module.expectedDataFileDownloads++;
18 (function() {
19 if (Module["ENVIRONMENT_IS_PTHREAD"] || Module["$ww"]) return;
20 var loadPackage = function(metadata) {
21 var PACKAGE_PATH = "";
22 if (typeof window === "object") {
23 PACKAGE_PATH = window["encodeURIComponent"](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf("/")) + "/")
24 } else if (typeof process === "undefined" && typeof location !== "undefined") {
25 PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf("/")) + "/")
26 }
27 var PACKAGE_NAME = "units.lib.data";
28 var REMOTE_PACKAGE_BASE = "units.lib.data";
29 if (typeof Module["locateFilePackage"] === "function" && !Module["locateFile"]) {
30 Module["locateFile"] = Module["locateFilePackage"];
31 err("warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)")
32 }
33 var REMOTE_PACKAGE_NAME = Module["locateFile"] ? Module["locateFile"](REMOTE_PACKAGE_BASE, "") : REMOTE_PACKAGE_BASE;
34 var REMOTE_PACKAGE_SIZE = metadata["remote_package_size"];
35
36 function fetchRemotePackage(packageName, packageSize, callback, errback) {
37 if (typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string") {
38 require("fs").readFile(packageName, function(err, contents) {
39 if (err) {
40 errback(err)
41 } else {
42 callback(contents.buffer)
43 }
44 });
45 return
46 }
47 var xhr = new XMLHttpRequest;
48 xhr.open("GET", packageName, true);
49 xhr.responseType = "arraybuffer";
50 xhr.onprogress = function(event) {
51 var url = packageName;
52 var size = packageSize;
53 if (event.total) size = event.total;
54 if (event.loaded) {
55 if (!xhr.addedTotal) {
56 xhr.addedTotal = true;
57 if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
58 Module.dataFileDownloads[url] = {
59 loaded: event.loaded,
60 total: size
61 }
62 } else {
63 Module.dataFileDownloads[url].loaded = event.loaded
64 }
65 var total = 0;
66 var loaded = 0;
67 var num = 0;
68 for (var download in Module.dataFileDownloads) {
69 var data = Module.dataFileDownloads[download];
70 total += data.total;
71 loaded += data.loaded;
72 num++
73 }
74 total = Math.ceil(total * Module.expectedDataFileDownloads / num);
75 if (Module["setStatus"]) Module["setStatus"](`Downloading data... (${loaded}/${total})`)
76 } else if (!Module.dataFileDownloads) {
77 if (Module["setStatus"]) Module["setStatus"]("Downloading data...")
78 }
79 };
80 xhr.onerror = function(event) {
81 throw new Error("NetworkError for: " + packageName)
82 };
83 xhr.onload = function(event) {
84 if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || xhr.status == 0 && xhr.response) {
85 var packageData = xhr.response;
86 callback(packageData)
87 } else {
88 throw new Error(xhr.statusText + " : " + xhr.responseURL)
89 }
90 };
91 xhr.send(null)
92 }
93
94 function handleError(error) {
95 console.error("package error:", error)
96 }
97 var fetchedCallback = null;
98 var fetched = Module["getPreloadedPackage"] ? Module["getPreloadedPackage"](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null;
99 if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
100 if (fetchedCallback) {
101 fetchedCallback(data);
102 fetchedCallback = null
103 } else {
104 fetched = data
105 }
106 }, handleError);
107
108 function runWithFS() {
109 function assert(check, msg) {
110 if (!check) throw msg + (new Error).stack
111 }
112
113 function DataRequest(start, end, audio) {
114 this.start = start;
115 this.end = end;
116 this.audio = audio
117 }
118 DataRequest.prototype = {
119 requests: {},
120 open: function(mode, name) {
121 this.name = name;
122 this.requests[name] = this;
123 Module["addRunDependency"](`fp ${this.name}`)
124 },
125 send: function() {},
126 onload: function() {
127 var byteArray = this.byteArray.subarray(this.start, this.end);
128 this.finish(byteArray)
129 },
130 finish: function(byteArray) {
131 var that = this;
132 Module["FS_createDataFile"](this.name, null, byteArray, true, true, true);
133 Module["removeRunDependency"](`fp ${that.name}`);
134 this.requests[this.name] = null
135 }
136 };
137 var files = metadata["files"];
138 for (var i = 0; i < files.length; ++i) {
139 new DataRequest(files[i]["start"], files[i]["end"], files[i]["audio"] || 0).open("GET", files[i]["filename"])
140 }
141
142 function processPackageData(arrayBuffer) {
143 assert(arrayBuffer, "Loading data file failed.");
144 assert(arrayBuffer.constructor.name === ArrayBuffer.name, "bad input to processPackageData");
145 var byteArray = new Uint8Array(arrayBuffer);
146 DataRequest.prototype.byteArray = byteArray;
147 var files = metadata["files"];
148 for (var i = 0; i < files.length; ++i) {
149 DataRequest.prototype.requests[files[i].filename].onload()
150 }
151 Module["removeRunDependency"]("datafile_units.lib.data")
152 }
153 Module["addRunDependency"]("datafile_units.lib.data");
154 if (!Module.preloadResults) Module.preloadResults = {};
155 Module.preloadResults[PACKAGE_NAME] = {
156 fromCache: false
157 };
158 if (fetched) {
159 processPackageData(fetched);
160 fetched = null
161 } else {
162 fetchedCallback = processPackageData
163 }
164 }
165 if (Module["calledRun"]) {
166 runWithFS()
167 } else {
168 if (!Module["preRun"]) Module["preRun"] = [];
169 Module["preRun"].push(runWithFS)
170 }
171 };
172 loadPackage({
173 "files": [{
174 "filename": "/cpi.units",
175 "start": 0,
176 "end": 44458
177 }, {
178 "filename": "/currency.units",
179 "start": 44458,
180 "end": 59060
181 }, {
182 "filename": "/definitions.units",
183 "start": 59060,
184 "end": 419653
185 }, {
186 "filename": "/elements.units",
187 "start": 419653,
188 "end": 571034
189 }],
190 "remote_package_size": 571034
191 })
192 })();
193 globalThis.printBuffer = "";
194 Module["print"] = function(out) {
195 globalThis.printBuffer += out + "\n"
196 };
197 var moduleOverrides = Object.assign({}, Module);
198 var arguments_ = [];
199 var thisProgram = "./this.program";
200 var quit_ = (status, toThrow) => {
201 throw toThrow
202 };
203 var ENVIRONMENT_IS_WEB = typeof window == "object";
204 var ENVIRONMENT_IS_WORKER = typeof importScripts == "function";
205 var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
206 var scriptDirectory = "";
207
208 function locateFile(path) {
209 if (Module["locateFile"]) {
210 return Module["locateFile"](path, scriptDirectory)
211 }
212 return scriptDirectory + path
213 }
214 var read_, readAsync, readBinary;
215 if (ENVIRONMENT_IS_NODE) {
216 var fs = require("fs");
217 var nodePath = require("path");
218 if (ENVIRONMENT_IS_WORKER) {
219 scriptDirectory = nodePath.dirname(scriptDirectory) + "/"
220 } else {
221 scriptDirectory = __dirname + "/"
222 }
223 read_ = (filename, binary) => {
224 filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
225 return fs.readFileSync(filename, binary ? undefined : "utf8")
226 };
227 readBinary = filename => {
228 var ret = read_(filename, true);
229 if (!ret.buffer) {
230 ret = new Uint8Array(ret)
231 }
232 return ret
233 };
234 readAsync = (filename, onload, onerror, binary = true) => {
235 filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
236 fs.readFile(filename, binary ? undefined : "utf8", (err, data) => {
237 if (err) onerror(err);
238 else onload(binary ? data.buffer : data)
239 })
240 };
241 if (!Module["thisProgram"] && process.argv.length > 1) {
242 thisProgram = process.argv[1].replace(/\\/g, "/")
243 }
244 arguments_ = process.argv.slice(2);
245 quit_ = (status, toThrow) => {
246 process.exitCode = status;
247 throw toThrow
248 }
249 } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
250 if (ENVIRONMENT_IS_WORKER) {
251 scriptDirectory = self.location.href
252 } else if (typeof document != "undefined" && document.currentScript) {
253 scriptDirectory = document.currentScript.src
254 }
255 if (_scriptDir) {
256 scriptDirectory = _scriptDir
257 }
258 if (scriptDirectory.startsWith("blob:")) {
259 scriptDirectory = ""
260 } else {
261 scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1)
262 } {
263 read_ = url => {
264 var xhr = new XMLHttpRequest;
265 xhr.open("GET", url, false);
266 xhr.send(null);
267 return xhr.responseText
268 };
269 if (ENVIRONMENT_IS_WORKER) {
270 readBinary = url => {
271 var xhr = new XMLHttpRequest;
272 xhr.open("GET", url, false);
273 xhr.responseType = "arraybuffer";
274 xhr.send(null);
275 return new Uint8Array(xhr.response)
276 }
277 }
278 readAsync = (url, onload, onerror) => {
279 var xhr = new XMLHttpRequest;
280 xhr.open("GET", url, true);
281 xhr.responseType = "arraybuffer";
282 xhr.onload = () => {
283 if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
284 onload(xhr.response);
285 return
286 }
287 onerror()
288 };
289 xhr.onerror = onerror;
290 xhr.send(null)
291 }
292 }
293 } else {}
294 var out = Module["print"] || console.log.bind(console);
295 var err = Module["printErr"] || console.error.bind(console);
296 Object.assign(Module, moduleOverrides);
297 moduleOverrides = null;
298 if (Module["arguments"]) arguments_ = Module["arguments"];
299 if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
300 if (Module["quit"]) quit_ = Module["quit"];
301 var wasmBinary;
302 if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
303 if (typeof WebAssembly != "object") {
304 abort("no native wasm support detected")
305 }
306 var wasmMemory;
307 var ABORT = false;
308 var EXITSTATUS;
309 var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
310
311 function updateMemoryViews() {
312 var b = wasmMemory.buffer;
313 Module["HEAP8"] = HEAP8 = new Int8Array(b);
314 Module["HEAP16"] = HEAP16 = new Int16Array(b);
315 Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
316 Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
317 Module["HEAP32"] = HEAP32 = new Int32Array(b);
318 Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
319 Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
320 Module["HEAPF64"] = HEAPF64 = new Float64Array(b)
321 }
322 var __ATPRERUN__ = [];
323 var __ATINIT__ = [];
324 var __ATPOSTRUN__ = [];
325 var runtimeInitialized = false;
326
327 function preRun() {
328 if (Module["preRun"]) {
329 if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
330 while (Module["preRun"].length) {
331 addOnPreRun(Module["preRun"].shift())
332 }
333 }
334 callRuntimeCallbacks(__ATPRERUN__)
335 }
336
337 function initRuntime() {
338 runtimeInitialized = true;
339 if (!Module["noFSInit"] && !FS.init.initialized) FS.init();
340 FS.ignorePermissions = false;
341 TTY.init();
342 callRuntimeCallbacks(__ATINIT__)
343 }
344
345 function postRun() {
346 if (Module["postRun"]) {
347 if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
348 while (Module["postRun"].length) {
349 addOnPostRun(Module["postRun"].shift())
350 }
351 }
352 callRuntimeCallbacks(__ATPOSTRUN__)
353 }
354
355 function addOnPreRun(cb) {
356 __ATPRERUN__.unshift(cb)
357 }
358
359 function addOnInit(cb) {
360 __ATINIT__.unshift(cb)
361 }
362
363 function addOnPostRun(cb) {
364 __ATPOSTRUN__.unshift(cb)
365 }
366 var runDependencies = 0;
367 var runDependencyWatcher = null;
368 var dependenciesFulfilled = null;
369
370 function getUniqueRunDependency(id) {
371 return id
372 }
373
374 function addRunDependency(id) {
375 runDependencies++;
376 Module["monitorRunDependencies"]?.(runDependencies)
377 }
378
379 function removeRunDependency(id) {
380 runDependencies--;
381 Module["monitorRunDependencies"]?.(runDependencies);
382 if (runDependencies == 0) {
383 if (runDependencyWatcher !== null) {
384 clearInterval(runDependencyWatcher);
385 runDependencyWatcher = null
386 }
387 if (dependenciesFulfilled) {
388 var callback = dependenciesFulfilled;
389 dependenciesFulfilled = null;
390 callback()
391 }
392 }
393 }
394
395 function abort(what) {
396 Module["onAbort"]?.(what);
397 what = "Aborted(" + what + ")";
398 err(what);
399 ABORT = true;
400 EXITSTATUS = 1;
401 what += ". Build with -sASSERTIONS for more info.";
402 var e = new WebAssembly.RuntimeError(what);
403 readyPromiseReject(e);
404 throw e
405 }
406 var dataURIPrefix = "data:application/octet-stream;base64,";
407 var isDataURI = filename => filename.startsWith(dataURIPrefix);
408 var isFileURI = filename => filename.startsWith("file://");
409 var wasmBinaryFile;
410 wasmBinaryFile = "units.lib.wasm";
411 if (!isDataURI(wasmBinaryFile)) {
412 wasmBinaryFile = locateFile(wasmBinaryFile)
413 }
414
415 function getBinarySync(file) {
416 if (file == wasmBinaryFile && wasmBinary) {
417 return new Uint8Array(wasmBinary)
418 }
419 if (readBinary) {
420 return readBinary(file)
421 }
422 throw "both async and sync fetching of the wasm failed"
423 }
424
425 function getBinaryPromise(binaryFile) {
426 if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
427 if (typeof fetch == "function" && !isFileURI(binaryFile)) {
428 return fetch(binaryFile, {
429 credentials: "same-origin"
430 }).then(response => {
431 if (!response["ok"]) {
432 throw `failed to load wasm binary file at '${binaryFile}'`
433 }
434 return response["arrayBuffer"]()
435 }).catch(() => getBinarySync(binaryFile))
436 } else if (readAsync) {
437 return new Promise((resolve, reject) => {
438 readAsync(binaryFile, response => resolve(new Uint8Array(response)), reject)
439 })
440 }
441 }
442 return Promise.resolve().then(() => getBinarySync(binaryFile))
443 }
444
445 function instantiateArrayBuffer(binaryFile, imports, receiver) {
446 return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(receiver, reason => {
447 err(`failed to asynchronously prepare wasm: ${reason}`);
448 abort(reason)
449 })
450 }
451
452 function instantiateAsync(binary, binaryFile, imports, callback) {
453 if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE && typeof fetch == "function") {
454 return fetch(binaryFile, {
455 credentials: "same-origin"
456 }).then(response => {
457 var result = WebAssembly.instantiateStreaming(response, imports);
458 return result.then(callback, function(reason) {
459 err(`wasm streaming compile failed: ${reason}`);
460 err("falling back to ArrayBuffer instantiation");
461 return instantiateArrayBuffer(binaryFile, imports, callback)
462 })
463 })
464 }
465 return instantiateArrayBuffer(binaryFile, imports, callback)
466 }
467
468 function createWasm() {
469 var info = {
470 "a": wasmImports
471 };
472
473 function receiveInstance(instance, module) {
474 wasmExports = instance.exports;
475 wasmExports = Asyncify.instrumentWasmExports(wasmExports);
476 wasmMemory = wasmExports["o"];
477 updateMemoryViews();
478 addOnInit(wasmExports["p"]);
479 removeRunDependency("wasm-instantiate");
480 return wasmExports
481 }
482 addRunDependency("wasm-instantiate");
483
484 function receiveInstantiationResult(result) {
485 receiveInstance(result["instance"])
486 }
487 if (Module["instantiateWasm"]) {
488 try {
489 return Module["instantiateWasm"](info, receiveInstance)
490 } catch (e) {
491 err(`Module.instantiateWasm callback failed with error: ${e}`);
492 readyPromiseReject(e)
493 }
494 }
495 instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject);
496 return {}
497 }
498 var tempDouble;
499 var tempI64;
500
501 function ExitStatus(status) {
502 this.name = "ExitStatus";
503 this.message = `Program terminated with exit(${status})`;
504 this.status = status
505 }
506 var callRuntimeCallbacks = callbacks => {
507 while (callbacks.length > 0) {
508 callbacks.shift()(Module)
509 }
510 };
511 var noExitRuntime = Module["noExitRuntime"] || true;
512 var PATH = {
513 isAbs: path => path.charAt(0) === "/",
514 splitPath: filename => {
515 var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
516 return splitPathRe.exec(filename).slice(1)
517 },
518 normalizeArray: (parts, allowAboveRoot) => {
519 var up = 0;
520 for (var i = parts.length - 1; i >= 0; i--) {
521 var last = parts[i];
522 if (last === ".") {
523 parts.splice(i, 1)
524 } else if (last === "..") {
525 parts.splice(i, 1);
526 up++
527 } else if (up) {
528 parts.splice(i, 1);
529 up--
530 }
531 }
532 if (allowAboveRoot) {
533 for (; up; up--) {
534 parts.unshift("..")
535 }
536 }
537 return parts
538 },
539 normalize: path => {
540 var isAbsolute = PATH.isAbs(path),
541 trailingSlash = path.substr(-1) === "/";
542 path = PATH.normalizeArray(path.split("/").filter(p => !!p), !isAbsolute).join("/");
543 if (!path && !isAbsolute) {
544 path = "."
545 }
546 if (path && trailingSlash) {
547 path += "/"
548 }
549 return (isAbsolute ? "/" : "") + path
550 },
551 dirname: path => {
552 var result = PATH.splitPath(path),
553 root = result[0],
554 dir = result[1];
555 if (!root && !dir) {
556 return "."
557 }
558 if (dir) {
559 dir = dir.substr(0, dir.length - 1)
560 }
561 return root + dir
562 },
563 basename: path => {
564 if (path === "/") return "/";
565 path = PATH.normalize(path);
566 path = path.replace(/\/$/, "");
567 var lastSlash = path.lastIndexOf("/");
568 if (lastSlash === -1) return path;
569 return path.substr(lastSlash + 1)
570 },
571 join: (...paths) => PATH.normalize(paths.join("/")),
572 join2: (l, r) => PATH.normalize(l + "/" + r)
573 };
574 var initRandomFill = () => {
575 if (typeof crypto == "object" && typeof crypto["getRandomValues"] == "function") {
576 return view => crypto.getRandomValues(view)
577 } else if (ENVIRONMENT_IS_NODE) {
578 try {
579 var crypto_module = require("crypto");
580 var randomFillSync = crypto_module["randomFillSync"];
581 if (randomFillSync) {
582 return view => crypto_module["randomFillSync"](view)
583 }
584 var randomBytes = crypto_module["randomBytes"];
585 return view => (view.set(randomBytes(view.byteLength)), view)
586 } catch (e) {}
587 }
588 abort("initRandomDevice")
589 };
590 var randomFill = view => (randomFill = initRandomFill())(view);
591 var PATH_FS = {
592 resolve: (...args) => {
593 var resolvedPath = "",
594 resolvedAbsolute = false;
595 for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
596 var path = i >= 0 ? args[i] : FS.cwd();
597 if (typeof path != "string") {
598 throw new TypeError("Arguments to path.resolve must be strings")
599 } else if (!path) {
600 return ""
601 }
602 resolvedPath = path + "/" + resolvedPath;
603 resolvedAbsolute = PATH.isAbs(path)
604 }
605 resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter(p => !!p), !resolvedAbsolute).join("/");
606 return (resolvedAbsolute ? "/" : "") + resolvedPath || "."
607 },
608 relative: (from, to) => {
609 from = PATH_FS.resolve(from).substr(1);
610 to = PATH_FS.resolve(to).substr(1);
611
612 function trim(arr) {
613 var start = 0;
614 for (; start < arr.length; start++) {
615 if (arr[start] !== "") break
616 }
617 var end = arr.length - 1;
618 for (; end >= 0; end--) {
619 if (arr[end] !== "") break
620 }
621 if (start > end) return [];
622 return arr.slice(start, end - start + 1)
623 }
624 var fromParts = trim(from.split("/"));
625 var toParts = trim(to.split("/"));
626 var length = Math.min(fromParts.length, toParts.length);
627 var samePartsLength = length;
628 for (var i = 0; i < length; i++) {
629 if (fromParts[i] !== toParts[i]) {
630 samePartsLength = i;
631 break
632 }
633 }
634 var outputParts = [];
635 for (var i = samePartsLength; i < fromParts.length; i++) {
636 outputParts.push("..")
637 }
638 outputParts = outputParts.concat(toParts.slice(samePartsLength));
639 return outputParts.join("/")
640 }
641 };
642 var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined;
643 var UTF8ArrayToString = (heapOrArray, idx, maxBytesToRead) => {
644 var endIdx = idx + maxBytesToRead;
645 var endPtr = idx;
646 while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
647 if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
648 return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr))
649 }
650 var str = "";
651 while (idx < endPtr) {
652 var u0 = heapOrArray[idx++];
653 if (!(u0 & 128)) {
654 str += String.fromCharCode(u0);
655 continue
656 }
657 var u1 = heapOrArray[idx++] & 63;
658 if ((u0 & 224) == 192) {
659 str += String.fromCharCode((u0 & 31) << 6 | u1);
660 continue
661 }
662 var u2 = heapOrArray[idx++] & 63;
663 if ((u0 & 240) == 224) {
664 u0 = (u0 & 15) << 12 | u1 << 6 | u2
665 } else {
666 u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63
667 }
668 if (u0 < 65536) {
669 str += String.fromCharCode(u0)
670 } else {
671 var ch = u0 - 65536;
672 str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023)
673 }
674 }
675 return str
676 };
677 var FS_stdin_getChar_buffer = [];
678 var lengthBytesUTF8 = str => {
679 var len = 0;
680 for (var i = 0; i < str.length; ++i) {
681 var c = str.charCodeAt(i);
682 if (c <= 127) {
683 len++
684 } else if (c <= 2047) {
685 len += 2
686 } else if (c >= 55296 && c <= 57343) {
687 len += 4;
688 ++i
689 } else {
690 len += 3
691 }
692 }
693 return len
694 };
695 var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
696 if (!(maxBytesToWrite > 0)) return 0;
697 var startIdx = outIdx;
698 var endIdx = outIdx + maxBytesToWrite - 1;
699 for (var i = 0; i < str.length; ++i) {
700 var u = str.charCodeAt(i);
701 if (u >= 55296 && u <= 57343) {
702 var u1 = str.charCodeAt(++i);
703 u = 65536 + ((u & 1023) << 10) | u1 & 1023
704 }
705 if (u <= 127) {
706 if (outIdx >= endIdx) break;
707 heap[outIdx++] = u
708 } else if (u <= 2047) {
709 if (outIdx + 1 >= endIdx) break;
710 heap[outIdx++] = 192 | u >> 6;
711 heap[outIdx++] = 128 | u & 63
712 } else if (u <= 65535) {
713 if (outIdx + 2 >= endIdx) break;
714 heap[outIdx++] = 224 | u >> 12;
715 heap[outIdx++] = 128 | u >> 6 & 63;
716 heap[outIdx++] = 128 | u & 63
717 } else {
718 if (outIdx + 3 >= endIdx) break;
719 heap[outIdx++] = 240 | u >> 18;
720 heap[outIdx++] = 128 | u >> 12 & 63;
721 heap[outIdx++] = 128 | u >> 6 & 63;
722 heap[outIdx++] = 128 | u & 63
723 }
724 }
725 heap[outIdx] = 0;
726 return outIdx - startIdx
727 };
728
729 function intArrayFromString(stringy, dontAddNull, length) {
730 var len = length > 0 ? length : lengthBytesUTF8(stringy) + 1;
731 var u8array = new Array(len);
732 var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
733 if (dontAddNull) u8array.length = numBytesWritten;
734 return u8array
735 }
736 var FS_stdin_getChar = () => {
737 if (!FS_stdin_getChar_buffer.length) {
738 var result = null;
739 if (ENVIRONMENT_IS_NODE) {
740 var BUFSIZE = 256;
741 var buf = Buffer.alloc(BUFSIZE);
742 var bytesRead = 0;
743 var fd = process.stdin.fd;
744 try {
745 bytesRead = fs.readSync(fd, buf)
746 } catch (e) {
747 if (e.toString().includes("EOF")) bytesRead = 0;
748 else throw e
749 }
750 if (bytesRead > 0) {
751 result = buf.slice(0, bytesRead).toString("utf-8")
752 } else {
753 result = null
754 }
755 } else if (typeof window != "undefined" && typeof window.prompt == "function") {
756 result = window.prompt("Input: ");
757 if (result !== null) {
758 result += "\n"
759 }
760 } else if (typeof readline == "function") {
761 result = readline();
762 if (result !== null) {
763 result += "\n"
764 }
765 }
766 if (!result) {
767 return null
768 }
769 FS_stdin_getChar_buffer = intArrayFromString(result, true)
770 }
771 return FS_stdin_getChar_buffer.shift()
772 };
773 var TTY = {
774 ttys: [],
775 init() {},
776 shutdown() {},
777 register(dev, ops) {
778 TTY.ttys[dev] = {
779 input: [],
780 output: [],
781 ops: ops
782 };
783 FS.registerDevice(dev, TTY.stream_ops)
784 },
785 stream_ops: {
786 open(stream) {
787 var tty = TTY.ttys[stream.node.rdev];
788 if (!tty) {
789 throw new FS.ErrnoError(43)
790 }
791 stream.tty = tty;
792 stream.seekable = false
793 },
794 close(stream) {
795 stream.tty.ops.fsync(stream.tty)
796 },
797 fsync(stream) {
798 stream.tty.ops.fsync(stream.tty)
799 },
800 read(stream, buffer, offset, length, pos) {
801 if (!stream.tty || !stream.tty.ops.get_char) {
802 throw new FS.ErrnoError(60)
803 }
804 var bytesRead = 0;
805 for (var i = 0; i < length; i++) {
806 var result;
807 try {
808 result = stream.tty.ops.get_char(stream.tty)
809 } catch (e) {
810 throw new FS.ErrnoError(29)
811 }
812 if (result === undefined && bytesRead === 0) {
813 throw new FS.ErrnoError(6)
814 }
815 if (result === null || result === undefined) break;
816 bytesRead++;
817 buffer[offset + i] = result
818 }
819 if (bytesRead) {
820 stream.node.timestamp = Date.now()
821 }
822 return bytesRead
823 },
824 write(stream, buffer, offset, length, pos) {
825 if (!stream.tty || !stream.tty.ops.put_char) {
826 throw new FS.ErrnoError(60)
827 }
828 try {
829 for (var i = 0; i < length; i++) {
830 stream.tty.ops.put_char(stream.tty, buffer[offset + i])
831 }
832 } catch (e) {
833 throw new FS.ErrnoError(29)
834 }
835 if (length) {
836 stream.node.timestamp = Date.now()
837 }
838 return i
839 }
840 },
841 default_tty_ops: {
842 get_char(tty) {
843 return FS_stdin_getChar()
844 },
845 put_char(tty, val) {
846 if (val === null || val === 10) {
847 out(UTF8ArrayToString(tty.output, 0));
848 tty.output = []
849 } else {
850 if (val != 0) tty.output.push(val)
851 }
852 },
853 fsync(tty) {
854 if (tty.output && tty.output.length > 0) {
855 out(UTF8ArrayToString(tty.output, 0));
856 tty.output = []
857 }
858 },
859 ioctl_tcgets(tty) {
860 return {
861 c_iflag: 25856,
862 c_oflag: 5,
863 c_cflag: 191,
864 c_lflag: 35387,
865 c_cc: [3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
866 }
867 },
868 ioctl_tcsets(tty, optional_actions, data) {
869 return 0
870 },
871 ioctl_tiocgwinsz(tty) {
872 return [24, 80]
873 }
874 },
875 default_tty1_ops: {
876 put_char(tty, val) {
877 if (val === null || val === 10) {
878 err(UTF8ArrayToString(tty.output, 0));
879 tty.output = []
880 } else {
881 if (val != 0) tty.output.push(val)
882 }
883 },
884 fsync(tty) {
885 if (tty.output && tty.output.length > 0) {
886 err(UTF8ArrayToString(tty.output, 0));
887 tty.output = []
888 }
889 }
890 }
891 };
892 var mmapAlloc = size => {
893 abort()
894 };
895 var MEMFS = {
896 ops_table: null,
897 mount(mount) {
898 return MEMFS.createNode(null, "/", 16384 | 511, 0)
899 },
900 createNode(parent, name, mode, dev) {
901 if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
902 throw new FS.ErrnoError(63)
903 }
904 MEMFS.ops_table ||= {
905 dir: {
906 node: {
907 getattr: MEMFS.node_ops.getattr,
908 setattr: MEMFS.node_ops.setattr,
909 lookup: MEMFS.node_ops.lookup,
910 mknod: MEMFS.node_ops.mknod,
911 rename: MEMFS.node_ops.rename,
912 unlink: MEMFS.node_ops.unlink,
913 rmdir: MEMFS.node_ops.rmdir,
914 readdir: MEMFS.node_ops.readdir,
915 symlink: MEMFS.node_ops.symlink
916 },
917 stream: {
918 llseek: MEMFS.stream_ops.llseek
919 }
920 },
921 file: {
922 node: {
923 getattr: MEMFS.node_ops.getattr,
924 setattr: MEMFS.node_ops.setattr
925 },
926 stream: {
927 llseek: MEMFS.stream_ops.llseek,
928 read: MEMFS.stream_ops.read,
929 write: MEMFS.stream_ops.write,
930 allocate: MEMFS.stream_ops.allocate,
931 mmap: MEMFS.stream_ops.mmap,
932 msync: MEMFS.stream_ops.msync
933 }
934 },
935 link: {
936 node: {
937 getattr: MEMFS.node_ops.getattr,
938 setattr: MEMFS.node_ops.setattr,
939 readlink: MEMFS.node_ops.readlink
940 },
941 stream: {}
942 },
943 chrdev: {
944 node: {
945 getattr: MEMFS.node_ops.getattr,
946 setattr: MEMFS.node_ops.setattr
947 },
948 stream: FS.chrdev_stream_ops
949 }
950 };
951 var node = FS.createNode(parent, name, mode, dev);
952 if (FS.isDir(node.mode)) {
953 node.node_ops = MEMFS.ops_table.dir.node;
954 node.stream_ops = MEMFS.ops_table.dir.stream;
955 node.contents = {}
956 } else if (FS.isFile(node.mode)) {
957 node.node_ops = MEMFS.ops_table.file.node;
958 node.stream_ops = MEMFS.ops_table.file.stream;
959 node.usedBytes = 0;
960 node.contents = null
961 } else if (FS.isLink(node.mode)) {
962 node.node_ops = MEMFS.ops_table.link.node;
963 node.stream_ops = MEMFS.ops_table.link.stream
964 } else if (FS.isChrdev(node.mode)) {
965 node.node_ops = MEMFS.ops_table.chrdev.node;
966 node.stream_ops = MEMFS.ops_table.chrdev.stream
967 }
968 node.timestamp = Date.now();
969 if (parent) {
970 parent.contents[name] = node;
971 parent.timestamp = node.timestamp
972 }
973 return node
974 },
975 getFileDataAsTypedArray(node) {
976 if (!node.contents) return new Uint8Array(0);
977 if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes);
978 return new Uint8Array(node.contents)
979 },
980 expandFileStorage(node, newCapacity) {
981 var prevCapacity = node.contents ? node.contents.length : 0;
982 if (prevCapacity >= newCapacity) return;
983 var CAPACITY_DOUBLING_MAX = 1024 * 1024;
984 newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125) >>> 0);
985 if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256);
986 var oldContents = node.contents;
987 node.contents = new Uint8Array(newCapacity);
988 if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0)
989 },
990 resizeFileStorage(node, newSize) {
991 if (node.usedBytes == newSize) return;
992 if (newSize == 0) {
993 node.contents = null;
994 node.usedBytes = 0
995 } else {
996 var oldContents = node.contents;
997 node.contents = new Uint8Array(newSize);
998 if (oldContents) {
999 node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)))
1000 }
1001 node.usedBytes = newSize
1002 }
1003 },
1004 node_ops: {
1005 getattr(node) {
1006 var attr = {};
1007 attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
1008 attr.ino = node.id;
1009 attr.mode = node.mode;
1010 attr.nlink = 1;
1011 attr.uid = 0;
1012 attr.gid = 0;
1013 attr.rdev = node.rdev;
1014 if (FS.isDir(node.mode)) {
1015 attr.size = 4096
1016 } else if (FS.isFile(node.mode)) {
1017 attr.size = node.usedBytes
1018 } else if (FS.isLink(node.mode)) {
1019 attr.size = node.link.length
1020 } else {
1021 attr.size = 0
1022 }
1023 attr.atime = new Date(node.timestamp);
1024 attr.mtime = new Date(node.timestamp);
1025 attr.ctime = new Date(node.timestamp);
1026 attr.blksize = 4096;
1027 attr.blocks = Math.ceil(attr.size / attr.blksize);
1028 return attr
1029 },
1030 setattr(node, attr) {
1031 if (attr.mode !== undefined) {
1032 node.mode = attr.mode
1033 }
1034 if (attr.timestamp !== undefined) {
1035 node.timestamp = attr.timestamp
1036 }
1037 if (attr.size !== undefined) {
1038 MEMFS.resizeFileStorage(node, attr.size)
1039 }
1040 },
1041 lookup(parent, name) {
1042 throw FS.genericErrors[44]
1043 },
1044 mknod(parent, name, mode, dev) {
1045 return MEMFS.createNode(parent, name, mode, dev)
1046 },
1047 rename(old_node, new_dir, new_name) {
1048 if (FS.isDir(old_node.mode)) {
1049 var new_node;
1050 try {
1051 new_node = FS.lookupNode(new_dir, new_name)
1052 } catch (e) {}
1053 if (new_node) {
1054 for (var i in new_node.contents) {
1055 throw new FS.ErrnoError(55)
1056 }
1057 }
1058 }
1059 delete old_node.parent.contents[old_node.name];
1060 old_node.parent.timestamp = Date.now();
1061 old_node.name = new_name;
1062 new_dir.contents[new_name] = old_node;
1063 new_dir.timestamp = old_node.parent.timestamp;
1064 old_node.parent = new_dir
1065 },
1066 unlink(parent, name) {
1067 delete parent.contents[name];
1068 parent.timestamp = Date.now()
1069 },
1070 rmdir(parent, name) {
1071 var node = FS.lookupNode(parent, name);
1072 for (var i in node.contents) {
1073 throw new FS.ErrnoError(55)
1074 }
1075 delete parent.contents[name];
1076 parent.timestamp = Date.now()
1077 },
1078 readdir(node) {
1079 var entries = [".", ".."];
1080 for (var key of Object.keys(node.contents)) {
1081 entries.push(key)
1082 }
1083 return entries
1084 },
1085 symlink(parent, newname, oldpath) {
1086 var node = MEMFS.createNode(parent, newname, 511 | 40960, 0);
1087 node.link = oldpath;
1088 return node
1089 },
1090 readlink(node) {
1091 if (!FS.isLink(node.mode)) {
1092 throw new FS.ErrnoError(28)
1093 }
1094 return node.link
1095 }
1096 },
1097 stream_ops: {
1098 read(stream, buffer, offset, length, position) {
1099 var contents = stream.node.contents;
1100 if (position >= stream.node.usedBytes) return 0;
1101 var size = Math.min(stream.node.usedBytes - position, length);
1102 if (size > 8 && contents.subarray) {
1103 buffer.set(contents.subarray(position, position + size), offset)
1104 } else {
1105 for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i]
1106 }
1107 return size
1108 },
1109 write(stream, buffer, offset, length, position, canOwn) {
1110 if (!length) return 0;
1111 var node = stream.node;
1112 node.timestamp = Date.now();
1113 if (buffer.subarray && (!node.contents || node.contents.subarray)) {
1114 if (canOwn) {
1115 node.contents = buffer.subarray(offset, offset + length);
1116 node.usedBytes = length;
1117 return length
1118 } else if (node.usedBytes === 0 && position === 0) {
1119 node.contents = buffer.slice(offset, offset + length);
1120 node.usedBytes = length;
1121 return length
1122 } else if (position + length <= node.usedBytes) {
1123 node.contents.set(buffer.subarray(offset, offset + length), position);
1124 return length
1125 }
1126 }
1127 MEMFS.expandFileStorage(node, position + length);
1128 if (node.contents.subarray && buffer.subarray) {
1129 node.contents.set(buffer.subarray(offset, offset + length), position)
1130 } else {
1131 for (var i = 0; i < length; i++) {
1132 node.contents[position + i] = buffer[offset + i]
1133 }
1134 }
1135 node.usedBytes = Math.max(node.usedBytes, position + length);
1136 return length
1137 },
1138 llseek(stream, offset, whence) {
1139 var position = offset;
1140 if (whence === 1) {
1141 position += stream.position
1142 } else if (whence === 2) {
1143 if (FS.isFile(stream.node.mode)) {
1144 position += stream.node.usedBytes
1145 }
1146 }
1147 if (position < 0) {
1148 throw new FS.ErrnoError(28)
1149 }
1150 return position
1151 },
1152 allocate(stream, offset, length) {
1153 MEMFS.expandFileStorage(stream.node, offset + length);
1154 stream.node.usedBytes = Math.max(stream.node.usedBytes, offset + length)
1155 },
1156 mmap(stream, length, position, prot, flags) {
1157 if (!FS.isFile(stream.node.mode)) {
1158 throw new FS.ErrnoError(43)
1159 }
1160 var ptr;
1161 var allocated;
1162 var contents = stream.node.contents;
1163 if (!(flags & 2) && contents.buffer === HEAP8.buffer) {
1164 allocated = false;
1165 ptr = contents.byteOffset
1166 } else {
1167 if (position > 0 || position + length < contents.length) {
1168 if (contents.subarray) {
1169 contents = contents.subarray(position, position + length)
1170 } else {
1171 contents = Array.prototype.slice.call(contents, position, position + length)
1172 }
1173 }
1174 allocated = true;
1175 ptr = mmapAlloc(length);
1176 if (!ptr) {
1177 throw new FS.ErrnoError(48)
1178 }
1179 HEAP8.set(contents, ptr)
1180 }
1181 return {
1182 ptr: ptr,
1183 allocated: allocated
1184 }
1185 },
1186 msync(stream, buffer, offset, length, mmapFlags) {
1187 MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
1188 return 0
1189 }
1190 }
1191 };
1192 var asyncLoad = (url, onload, onerror, noRunDep) => {
1193 var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : "";
1194 readAsync(url, arrayBuffer => {
1195 onload(new Uint8Array(arrayBuffer));
1196 if (dep) removeRunDependency(dep)
1197 }, event => {
1198 if (onerror) {
1199 onerror()
1200 } else {
1201 throw `Loading data file "${url}" failed.`
1202 }
1203 });
1204 if (dep) addRunDependency(dep)
1205 };
1206 var FS_createDataFile = (parent, name, fileData, canRead, canWrite, canOwn) => {
1207 FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn)
1208 };
1209 var preloadPlugins = Module["preloadPlugins"] || [];
1210 var FS_handledByPreloadPlugin = (byteArray, fullname, finish, onerror) => {
1211 if (typeof Browser != "undefined") Browser.init();
1212 var handled = false;
1213 preloadPlugins.forEach(plugin => {
1214 if (handled) return;
1215 if (plugin["canHandle"](fullname)) {
1216 plugin["handle"](byteArray, fullname, finish, onerror);
1217 handled = true
1218 }
1219 });
1220 return handled
1221 };
1222 var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
1223 var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1224 var dep = getUniqueRunDependency(`cp ${fullname}`);
1225
1226 function processData(byteArray) {
1227 function finish(byteArray) {
1228 preFinish?.();
1229 if (!dontCreateFile) {
1230 FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn)
1231 }
1232 onload?.();
1233 removeRunDependency(dep)
1234 }
1235 if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
1236 onerror?.();
1237 removeRunDependency(dep)
1238 })) {
1239 return
1240 }
1241 finish(byteArray)
1242 }
1243 addRunDependency(dep);
1244 if (typeof url == "string") {
1245 asyncLoad(url, processData, onerror)
1246 } else {
1247 processData(url)
1248 }
1249 };
1250 var FS_modeStringToFlags = str => {
1251 var flagModes = {
1252 "r": 0,
1253 "r+": 2,
1254 "w": 512 | 64 | 1,
1255 "w+": 512 | 64 | 2,
1256 "a": 1024 | 64 | 1,
1257 "a+": 1024 | 64 | 2
1258 };
1259 var flags = flagModes[str];
1260 if (typeof flags == "undefined") {
1261 throw new Error(`Unknown file open mode: ${str}`)
1262 }
1263 return flags
1264 };
1265 var FS_getMode = (canRead, canWrite) => {
1266 var mode = 0;
1267 if (canRead) mode |= 292 | 73;
1268 if (canWrite) mode |= 146;
1269 return mode
1270 };
1271 var FS = {
1272 root: null,
1273 mounts: [],
1274 devices: {},
1275 streams: [],
1276 nextInode: 1,
1277 nameTable: null,
1278 currentPath: "/",
1279 initialized: false,
1280 ignorePermissions: true,
1281 ErrnoError: class {
1282 constructor(errno) {
1283 this.name = "ErrnoError";
1284 this.errno = errno
1285 }
1286 },
1287 genericErrors: {},
1288 filesystems: null,
1289 syncFSRequests: 0,
1290 lookupPath(path, opts = {}) {
1291 path = PATH_FS.resolve(path);
1292 if (!path) return {
1293 path: "",
1294 node: null
1295 };
1296 var defaults = {
1297 follow_mount: true,
1298 recurse_count: 0
1299 };
1300 opts = Object.assign(defaults, opts);
1301 if (opts.recurse_count > 8) {
1302 throw new FS.ErrnoError(32)
1303 }
1304 var parts = path.split("/").filter(p => !!p);
1305 var current = FS.root;
1306 var current_path = "/";
1307 for (var i = 0; i < parts.length; i++) {
1308 var islast = i === parts.length - 1;
1309 if (islast && opts.parent) {
1310 break
1311 }
1312 current = FS.lookupNode(current, parts[i]);
1313 current_path = PATH.join2(current_path, parts[i]);
1314 if (FS.isMountpoint(current)) {
1315 if (!islast || islast && opts.follow_mount) {
1316 current = current.mounted.root
1317 }
1318 }
1319 if (!islast || opts.follow) {
1320 var count = 0;
1321 while (FS.isLink(current.mode)) {
1322 var link = FS.readlink(current_path);
1323 current_path = PATH_FS.resolve(PATH.dirname(current_path), link);
1324 var lookup = FS.lookupPath(current_path, {
1325 recurse_count: opts.recurse_count + 1
1326 });
1327 current = lookup.node;
1328 if (count++ > 40) {
1329 throw new FS.ErrnoError(32)
1330 }
1331 }
1332 }
1333 }
1334 return {
1335 path: current_path,
1336 node: current
1337 }
1338 },
1339 getPath(node) {
1340 var path;
1341 while (true) {
1342 if (FS.isRoot(node)) {
1343 var mount = node.mount.mountpoint;
1344 if (!path) return mount;
1345 return mount[mount.length - 1] !== "/" ? `${mount}/${path}` : mount + path
1346 }
1347 path = path ? `${node.name}/${path}` : node.name;
1348 node = node.parent
1349 }
1350 },
1351 hashName(parentid, name) {
1352 var hash = 0;
1353 for (var i = 0; i < name.length; i++) {
1354 hash = (hash << 5) - hash + name.charCodeAt(i) | 0
1355 }
1356 return (parentid + hash >>> 0) % FS.nameTable.length
1357 },
1358 hashAddNode(node) {
1359 var hash = FS.hashName(node.parent.id, node.name);
1360 node.name_next = FS.nameTable[hash];
1361 FS.nameTable[hash] = node
1362 },
1363 hashRemoveNode(node) {
1364 var hash = FS.hashName(node.parent.id, node.name);
1365 if (FS.nameTable[hash] === node) {
1366 FS.nameTable[hash] = node.name_next
1367 } else {
1368 var current = FS.nameTable[hash];
1369 while (current) {
1370 if (current.name_next === node) {
1371 current.name_next = node.name_next;
1372 break
1373 }
1374 current = current.name_next
1375 }
1376 }
1377 },
1378 lookupNode(parent, name) {
1379 var errCode = FS.mayLookup(parent);
1380 if (errCode) {
1381 throw new FS.ErrnoError(errCode)
1382 }
1383 var hash = FS.hashName(parent.id, name);
1384 for (var node = FS.nameTable[hash]; node; node = node.name_next) {
1385 var nodeName = node.name;
1386 if (node.parent.id === parent.id && nodeName === name) {
1387 return node
1388 }
1389 }
1390 return FS.lookup(parent, name)
1391 },
1392 createNode(parent, name, mode, rdev) {
1393 var node = new FS.FSNode(parent, name, mode, rdev);
1394 FS.hashAddNode(node);
1395 return node
1396 },
1397 destroyNode(node) {
1398 FS.hashRemoveNode(node)
1399 },
1400 isRoot(node) {
1401 return node === node.parent
1402 },
1403 isMountpoint(node) {
1404 return !!node.mounted
1405 },
1406 isFile(mode) {
1407 return (mode & 61440) === 32768
1408 },
1409 isDir(mode) {
1410 return (mode & 61440) === 16384
1411 },
1412 isLink(mode) {
1413 return (mode & 61440) === 40960
1414 },
1415 isChrdev(mode) {
1416 return (mode & 61440) === 8192
1417 },
1418 isBlkdev(mode) {
1419 return (mode & 61440) === 24576
1420 },
1421 isFIFO(mode) {
1422 return (mode & 61440) === 4096
1423 },
1424 isSocket(mode) {
1425 return (mode & 49152) === 49152
1426 },
1427 flagsToPermissionString(flag) {
1428 var perms = ["r", "w", "rw"][flag & 3];
1429 if (flag & 512) {
1430 perms += "w"
1431 }
1432 return perms
1433 },
1434 nodePermissions(node, perms) {
1435 if (FS.ignorePermissions) {
1436 return 0
1437 }
1438 if (perms.includes("r") && !(node.mode & 292)) {
1439 return 2
1440 } else if (perms.includes("w") && !(node.mode & 146)) {
1441 return 2
1442 } else if (perms.includes("x") && !(node.mode & 73)) {
1443 return 2
1444 }
1445 return 0
1446 },
1447 mayLookup(dir) {
1448 if (!FS.isDir(dir.mode)) return 54;
1449 var errCode = FS.nodePermissions(dir, "x");
1450 if (errCode) return errCode;
1451 if (!dir.node_ops.lookup) return 2;
1452 return 0
1453 },
1454 mayCreate(dir, name) {
1455 try {
1456 var node = FS.lookupNode(dir, name);
1457 return 20
1458 } catch (e) {}
1459 return FS.nodePermissions(dir, "wx")
1460 },
1461 mayDelete(dir, name, isdir) {
1462 var node;
1463 try {
1464 node = FS.lookupNode(dir, name)
1465 } catch (e) {
1466 return e.errno
1467 }
1468 var errCode = FS.nodePermissions(dir, "wx");
1469 if (errCode) {
1470 return errCode
1471 }
1472 if (isdir) {
1473 if (!FS.isDir(node.mode)) {
1474 return 54
1475 }
1476 if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
1477 return 10
1478 }
1479 } else {
1480 if (FS.isDir(node.mode)) {
1481 return 31
1482 }
1483 }
1484 return 0
1485 },
1486 mayOpen(node, flags) {
1487 if (!node) {
1488 return 44
1489 }
1490 if (FS.isLink(node.mode)) {
1491 return 32
1492 } else if (FS.isDir(node.mode)) {
1493 if (FS.flagsToPermissionString(flags) !== "r" || flags & 512) {
1494 return 31
1495 }
1496 }
1497 return FS.nodePermissions(node, FS.flagsToPermissionString(flags))
1498 },
1499 MAX_OPEN_FDS: 4096,
1500 nextfd() {
1501 for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
1502 if (!FS.streams[fd]) {
1503 return fd
1504 }
1505 }
1506 throw new FS.ErrnoError(33)
1507 },
1508 getStreamChecked(fd) {
1509 var stream = FS.getStream(fd);
1510 if (!stream) {
1511 throw new FS.ErrnoError(8)
1512 }
1513 return stream
1514 },
1515 getStream: fd => FS.streams[fd],
1516 createStream(stream, fd = -1) {
1517 if (!FS.FSStream) {
1518 FS.FSStream = function() {
1519 this.shared = {}
1520 };
1521 FS.FSStream.prototype = {};
1522 Object.defineProperties(FS.FSStream.prototype, {
1523 object: {
1524 get() {
1525 return this.node
1526 },
1527 set(val) {
1528 this.node = val
1529 }
1530 },
1531 isRead: {
1532 get() {
1533 return (this.flags & 2097155) !== 1
1534 }
1535 },
1536 isWrite: {
1537 get() {
1538 return (this.flags & 2097155) !== 0
1539 }
1540 },
1541 isAppend: {
1542 get() {
1543 return this.flags & 1024
1544 }
1545 },
1546 flags: {
1547 get() {
1548 return this.shared.flags
1549 },
1550 set(val) {
1551 this.shared.flags = val
1552 }
1553 },
1554 position: {
1555 get() {
1556 return this.shared.position
1557 },
1558 set(val) {
1559 this.shared.position = val
1560 }
1561 }
1562 })
1563 }
1564 stream = Object.assign(new FS.FSStream, stream);
1565 if (fd == -1) {
1566 fd = FS.nextfd()
1567 }
1568 stream.fd = fd;
1569 FS.streams[fd] = stream;
1570 return stream
1571 },
1572 closeStream(fd) {
1573 FS.streams[fd] = null
1574 },
1575 chrdev_stream_ops: {
1576 open(stream) {
1577 var device = FS.getDevice(stream.node.rdev);
1578 stream.stream_ops = device.stream_ops;
1579 stream.stream_ops.open?.(stream)
1580 },
1581 llseek() {
1582 throw new FS.ErrnoError(70)
1583 }
1584 },
1585 major: dev => dev >> 8,
1586 minor: dev => dev & 255,
1587 makedev: (ma, mi) => ma << 8 | mi,
1588 registerDevice(dev, ops) {
1589 FS.devices[dev] = {
1590 stream_ops: ops
1591 }
1592 },
1593 getDevice: dev => FS.devices[dev],
1594 getMounts(mount) {
1595 var mounts = [];
1596 var check = [mount];
1597 while (check.length) {
1598 var m = check.pop();
1599 mounts.push(m);
1600 check.push(...m.mounts)
1601 }
1602 return mounts
1603 },
1604 syncfs(populate, callback) {
1605 if (typeof populate == "function") {
1606 callback = populate;
1607 populate = false
1608 }
1609 FS.syncFSRequests++;
1610 if (FS.syncFSRequests > 1) {
1611 err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`)
1612 }
1613 var mounts = FS.getMounts(FS.root.mount);
1614 var completed = 0;
1615
1616 function doCallback(errCode) {
1617 FS.syncFSRequests--;
1618 return callback(errCode)
1619 }
1620
1621 function done(errCode) {
1622 if (errCode) {
1623 if (!done.errored) {
1624 done.errored = true;
1625 return doCallback(errCode)
1626 }
1627 return
1628 }
1629 if (++completed >= mounts.length) {
1630 doCallback(null)
1631 }
1632 }
1633 mounts.forEach(mount => {
1634 if (!mount.type.syncfs) {
1635 return done(null)
1636 }
1637 mount.type.syncfs(mount, populate, done)
1638 })
1639 },
1640 mount(type, opts, mountpoint) {
1641 var root = mountpoint === "/";
1642 var pseudo = !mountpoint;
1643 var node;
1644 if (root && FS.root) {
1645 throw new FS.ErrnoError(10)
1646 } else if (!root && !pseudo) {
1647 var lookup = FS.lookupPath(mountpoint, {
1648 follow_mount: false
1649 });
1650 mountpoint = lookup.path;
1651 node = lookup.node;
1652 if (FS.isMountpoint(node)) {
1653 throw new FS.ErrnoError(10)
1654 }
1655 if (!FS.isDir(node.mode)) {
1656 throw new FS.ErrnoError(54)
1657 }
1658 }
1659 var mount = {
1660 type: type,
1661 opts: opts,
1662 mountpoint: mountpoint,
1663 mounts: []
1664 };
1665 var mountRoot = type.mount(mount);
1666 mountRoot.mount = mount;
1667 mount.root = mountRoot;
1668 if (root) {
1669 FS.root = mountRoot
1670 } else if (node) {
1671 node.mounted = mount;
1672 if (node.mount) {
1673 node.mount.mounts.push(mount)
1674 }
1675 }
1676 return mountRoot
1677 },
1678 unmount(mountpoint) {
1679 var lookup = FS.lookupPath(mountpoint, {
1680 follow_mount: false
1681 });
1682 if (!FS.isMountpoint(lookup.node)) {
1683 throw new FS.ErrnoError(28)
1684 }
1685 var node = lookup.node;
1686 var mount = node.mounted;
1687 var mounts = FS.getMounts(mount);
1688 Object.keys(FS.nameTable).forEach(hash => {
1689 var current = FS.nameTable[hash];
1690 while (current) {
1691 var next = current.name_next;
1692 if (mounts.includes(current.mount)) {
1693 FS.destroyNode(current)
1694 }
1695 current = next
1696 }
1697 });
1698 node.mounted = null;
1699 var idx = node.mount.mounts.indexOf(mount);
1700 node.mount.mounts.splice(idx, 1)
1701 },
1702 lookup(parent, name) {
1703 return parent.node_ops.lookup(parent, name)
1704 },
1705 mknod(path, mode, dev) {
1706 var lookup = FS.lookupPath(path, {
1707 parent: true
1708 });
1709 var parent = lookup.node;
1710 var name = PATH.basename(path);
1711 if (!name || name === "." || name === "..") {
1712 throw new FS.ErrnoError(28)
1713 }
1714 var errCode = FS.mayCreate(parent, name);
1715 if (errCode) {
1716 throw new FS.ErrnoError(errCode)
1717 }
1718 if (!parent.node_ops.mknod) {
1719 throw new FS.ErrnoError(63)
1720 }
1721 return parent.node_ops.mknod(parent, name, mode, dev)
1722 },
1723 create(path, mode) {
1724 mode = mode !== undefined ? mode : 438;
1725 mode &= 4095;
1726 mode |= 32768;
1727 return FS.mknod(path, mode, 0)
1728 },
1729 mkdir(path, mode) {
1730 mode = mode !== undefined ? mode : 511;
1731 mode &= 511 | 512;
1732 mode |= 16384;
1733 return FS.mknod(path, mode, 0)
1734 },
1735 mkdirTree(path, mode) {
1736 var dirs = path.split("/");
1737 var d = "";
1738 for (var i = 0; i < dirs.length; ++i) {
1739 if (!dirs[i]) continue;
1740 d += "/" + dirs[i];
1741 try {
1742 FS.mkdir(d, mode)
1743 } catch (e) {
1744 if (e.errno != 20) throw e
1745 }
1746 }
1747 },
1748 mkdev(path, mode, dev) {
1749 if (typeof dev == "undefined") {
1750 dev = mode;
1751 mode = 438
1752 }
1753 mode |= 8192;
1754 return FS.mknod(path, mode, dev)
1755 },
1756 symlink(oldpath, newpath) {
1757 if (!PATH_FS.resolve(oldpath)) {
1758 throw new FS.ErrnoError(44)
1759 }
1760 var lookup = FS.lookupPath(newpath, {
1761 parent: true
1762 });
1763 var parent = lookup.node;
1764 if (!parent) {
1765 throw new FS.ErrnoError(44)
1766 }
1767 var newname = PATH.basename(newpath);
1768 var errCode = FS.mayCreate(parent, newname);
1769 if (errCode) {
1770 throw new FS.ErrnoError(errCode)
1771 }
1772 if (!parent.node_ops.symlink) {
1773 throw new FS.ErrnoError(63)
1774 }
1775 return parent.node_ops.symlink(parent, newname, oldpath)
1776 },
1777 rename(old_path, new_path) {
1778 var old_dirname = PATH.dirname(old_path);
1779 var new_dirname = PATH.dirname(new_path);
1780 var old_name = PATH.basename(old_path);
1781 var new_name = PATH.basename(new_path);
1782 var lookup, old_dir, new_dir;
1783 lookup = FS.lookupPath(old_path, {
1784 parent: true
1785 });
1786 old_dir = lookup.node;
1787 lookup = FS.lookupPath(new_path, {
1788 parent: true
1789 });
1790 new_dir = lookup.node;
1791 if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
1792 if (old_dir.mount !== new_dir.mount) {
1793 throw new FS.ErrnoError(75)
1794 }
1795 var old_node = FS.lookupNode(old_dir, old_name);
1796 var relative = PATH_FS.relative(old_path, new_dirname);
1797 if (relative.charAt(0) !== ".") {
1798 throw new FS.ErrnoError(28)
1799 }
1800 relative = PATH_FS.relative(new_path, old_dirname);
1801 if (relative.charAt(0) !== ".") {
1802 throw new FS.ErrnoError(55)
1803 }
1804 var new_node;
1805 try {
1806 new_node = FS.lookupNode(new_dir, new_name)
1807 } catch (e) {}
1808 if (old_node === new_node) {
1809 return
1810 }
1811 var isdir = FS.isDir(old_node.mode);
1812 var errCode = FS.mayDelete(old_dir, old_name, isdir);
1813 if (errCode) {
1814 throw new FS.ErrnoError(errCode)
1815 }
1816 errCode = new_node ? FS.mayDelete(new_dir, new_name, isdir) : FS.mayCreate(new_dir, new_name);
1817 if (errCode) {
1818 throw new FS.ErrnoError(errCode)
1819 }
1820 if (!old_dir.node_ops.rename) {
1821 throw new FS.ErrnoError(63)
1822 }
1823 if (FS.isMountpoint(old_node) || new_node && FS.isMountpoint(new_node)) {
1824 throw new FS.ErrnoError(10)
1825 }
1826 if (new_dir !== old_dir) {
1827 errCode = FS.nodePermissions(old_dir, "w");
1828 if (errCode) {
1829 throw new FS.ErrnoError(errCode)
1830 }
1831 }
1832 FS.hashRemoveNode(old_node);
1833 try {
1834 old_dir.node_ops.rename(old_node, new_dir, new_name)
1835 } catch (e) {
1836 throw e
1837 } finally {
1838 FS.hashAddNode(old_node)
1839 }
1840 },
1841 rmdir(path) {
1842 var lookup = FS.lookupPath(path, {
1843 parent: true
1844 });
1845 var parent = lookup.node;
1846 var name = PATH.basename(path);
1847 var node = FS.lookupNode(parent, name);
1848 var errCode = FS.mayDelete(parent, name, true);
1849 if (errCode) {
1850 throw new FS.ErrnoError(errCode)
1851 }
1852 if (!parent.node_ops.rmdir) {
1853 throw new FS.ErrnoError(63)
1854 }
1855 if (FS.isMountpoint(node)) {
1856 throw new FS.ErrnoError(10)
1857 }
1858 parent.node_ops.rmdir(parent, name);
1859 FS.destroyNode(node)
1860 },
1861 readdir(path) {
1862 var lookup = FS.lookupPath(path, {
1863 follow: true
1864 });
1865 var node = lookup.node;
1866 if (!node.node_ops.readdir) {
1867 throw new FS.ErrnoError(54)
1868 }
1869 return node.node_ops.readdir(node)
1870 },
1871 unlink(path) {
1872 var lookup = FS.lookupPath(path, {
1873 parent: true
1874 });
1875 var parent = lookup.node;
1876 if (!parent) {
1877 throw new FS.ErrnoError(44)
1878 }
1879 var name = PATH.basename(path);
1880 var node = FS.lookupNode(parent, name);
1881 var errCode = FS.mayDelete(parent, name, false);
1882 if (errCode) {
1883 throw new FS.ErrnoError(errCode)
1884 }
1885 if (!parent.node_ops.unlink) {
1886 throw new FS.ErrnoError(63)
1887 }
1888 if (FS.isMountpoint(node)) {
1889 throw new FS.ErrnoError(10)
1890 }
1891 parent.node_ops.unlink(parent, name);
1892 FS.destroyNode(node)
1893 },
1894 readlink(path) {
1895 var lookup = FS.lookupPath(path);
1896 var link = lookup.node;
1897 if (!link) {
1898 throw new FS.ErrnoError(44)
1899 }
1900 if (!link.node_ops.readlink) {
1901 throw new FS.ErrnoError(28)
1902 }
1903 return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link))
1904 },
1905 stat(path, dontFollow) {
1906 var lookup = FS.lookupPath(path, {
1907 follow: !dontFollow
1908 });
1909 var node = lookup.node;
1910 if (!node) {
1911 throw new FS.ErrnoError(44)
1912 }
1913 if (!node.node_ops.getattr) {
1914 throw new FS.ErrnoError(63)
1915 }
1916 return node.node_ops.getattr(node)
1917 },
1918 lstat(path) {
1919 return FS.stat(path, true)
1920 },
1921 chmod(path, mode, dontFollow) {
1922 var node;
1923 if (typeof path == "string") {
1924 var lookup = FS.lookupPath(path, {
1925 follow: !dontFollow
1926 });
1927 node = lookup.node
1928 } else {
1929 node = path
1930 }
1931 if (!node.node_ops.setattr) {
1932 throw new FS.ErrnoError(63)
1933 }
1934 node.node_ops.setattr(node, {
1935 mode: mode & 4095 | node.mode & ~4095,
1936 timestamp: Date.now()
1937 })
1938 },
1939 lchmod(path, mode) {
1940 FS.chmod(path, mode, true)
1941 },
1942 fchmod(fd, mode) {
1943 var stream = FS.getStreamChecked(fd);
1944 FS.chmod(stream.node, mode)
1945 },
1946 chown(path, uid, gid, dontFollow) {
1947 var node;
1948 if (typeof path == "string") {
1949 var lookup = FS.lookupPath(path, {
1950 follow: !dontFollow
1951 });
1952 node = lookup.node
1953 } else {
1954 node = path
1955 }
1956 if (!node.node_ops.setattr) {
1957 throw new FS.ErrnoError(63)
1958 }
1959 node.node_ops.setattr(node, {
1960 timestamp: Date.now()
1961 })
1962 },
1963 lchown(path, uid, gid) {
1964 FS.chown(path, uid, gid, true)
1965 },
1966 fchown(fd, uid, gid) {
1967 var stream = FS.getStreamChecked(fd);
1968 FS.chown(stream.node, uid, gid)
1969 },
1970 truncate(path, len) {
1971 if (len < 0) {
1972 throw new FS.ErrnoError(28)
1973 }
1974 var node;
1975 if (typeof path == "string") {
1976 var lookup = FS.lookupPath(path, {
1977 follow: true
1978 });
1979 node = lookup.node
1980 } else {
1981 node = path
1982 }
1983 if (!node.node_ops.setattr) {
1984 throw new FS.ErrnoError(63)
1985 }
1986 if (FS.isDir(node.mode)) {
1987 throw new FS.ErrnoError(31)
1988 }
1989 if (!FS.isFile(node.mode)) {
1990 throw new FS.ErrnoError(28)
1991 }
1992 var errCode = FS.nodePermissions(node, "w");
1993 if (errCode) {
1994 throw new FS.ErrnoError(errCode)
1995 }
1996 node.node_ops.setattr(node, {
1997 size: len,
1998 timestamp: Date.now()
1999 })
2000 },
2001 ftruncate(fd, len) {
2002 var stream = FS.getStreamChecked(fd);
2003 if ((stream.flags & 2097155) === 0) {
2004 throw new FS.ErrnoError(28)
2005 }
2006 FS.truncate(stream.node, len)
2007 },
2008 utime(path, atime, mtime) {
2009 var lookup = FS.lookupPath(path, {
2010 follow: true
2011 });
2012 var node = lookup.node;
2013 node.node_ops.setattr(node, {
2014 timestamp: Math.max(atime, mtime)
2015 })
2016 },
2017 open(path, flags, mode) {
2018 if (path === "") {
2019 throw new FS.ErrnoError(44)
2020 }
2021 flags = typeof flags == "string" ? FS_modeStringToFlags(flags) : flags;
2022 mode = typeof mode == "undefined" ? 438 : mode;
2023 if (flags & 64) {
2024 mode = mode & 4095 | 32768
2025 } else {
2026 mode = 0
2027 }
2028 var node;
2029 if (typeof path == "object") {
2030 node = path
2031 } else {
2032 path = PATH.normalize(path);
2033 try {
2034 var lookup = FS.lookupPath(path, {
2035 follow: !(flags & 131072)
2036 });
2037 node = lookup.node
2038 } catch (e) {}
2039 }
2040 var created = false;
2041 if (flags & 64) {
2042 if (node) {
2043 if (flags & 128) {
2044 throw new FS.ErrnoError(20)
2045 }
2046 } else {
2047 node = FS.mknod(path, mode, 0);
2048 created = true
2049 }
2050 }
2051 if (!node) {
2052 throw new FS.ErrnoError(44)
2053 }
2054 if (FS.isChrdev(node.mode)) {
2055 flags &= ~512
2056 }
2057 if (flags & 65536 && !FS.isDir(node.mode)) {
2058 throw new FS.ErrnoError(54)
2059 }
2060 if (!created) {
2061 var errCode = FS.mayOpen(node, flags);
2062 if (errCode) {
2063 throw new FS.ErrnoError(errCode)
2064 }
2065 }
2066 if (flags & 512 && !created) {
2067 FS.truncate(node, 0)
2068 }
2069 flags &= ~(128 | 512 | 131072);
2070 var stream = FS.createStream({
2071 node: node,
2072 path: FS.getPath(node),
2073 flags: flags,
2074 seekable: true,
2075 position: 0,
2076 stream_ops: node.stream_ops,
2077 ungotten: [],
2078 error: false
2079 });
2080 if (stream.stream_ops.open) {
2081 stream.stream_ops.open(stream)
2082 }
2083 if (Module["logReadFiles"] && !(flags & 1)) {
2084 if (!FS.readFiles) FS.readFiles = {};
2085 if (!(path in FS.readFiles)) {
2086 FS.readFiles[path] = 1
2087 }
2088 }
2089 return stream
2090 },
2091 close(stream) {
2092 if (FS.isClosed(stream)) {
2093 throw new FS.ErrnoError(8)
2094 }
2095 if (stream.getdents) stream.getdents = null;
2096 try {
2097 if (stream.stream_ops.close) {
2098 stream.stream_ops.close(stream)
2099 }
2100 } catch (e) {
2101 throw e
2102 } finally {
2103 FS.closeStream(stream.fd)
2104 }
2105 stream.fd = null
2106 },
2107 isClosed(stream) {
2108 return stream.fd === null
2109 },
2110 llseek(stream, offset, whence) {
2111 if (FS.isClosed(stream)) {
2112 throw new FS.ErrnoError(8)
2113 }
2114 if (!stream.seekable || !stream.stream_ops.llseek) {
2115 throw new FS.ErrnoError(70)
2116 }
2117 if (whence != 0 && whence != 1 && whence != 2) {
2118 throw new FS.ErrnoError(28)
2119 }
2120 stream.position = stream.stream_ops.llseek(stream, offset, whence);
2121 stream.ungotten = [];
2122 return stream.position
2123 },
2124 read(stream, buffer, offset, length, position) {
2125 if (length < 0 || position < 0) {
2126 throw new FS.ErrnoError(28)
2127 }
2128 if (FS.isClosed(stream)) {
2129 throw new FS.ErrnoError(8)
2130 }
2131 if ((stream.flags & 2097155) === 1) {
2132 throw new FS.ErrnoError(8)
2133 }
2134 if (FS.isDir(stream.node.mode)) {
2135 throw new FS.ErrnoError(31)
2136 }
2137 if (!stream.stream_ops.read) {
2138 throw new FS.ErrnoError(28)
2139 }
2140 var seeking = typeof position != "undefined";
2141 if (!seeking) {
2142 position = stream.position
2143 } else if (!stream.seekable) {
2144 throw new FS.ErrnoError(70)
2145 }
2146 var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
2147 if (!seeking) stream.position += bytesRead;
2148 return bytesRead
2149 },
2150 write(stream, buffer, offset, length, position, canOwn) {
2151 if (length < 0 || position < 0) {
2152 throw new FS.ErrnoError(28)
2153 }
2154 if (FS.isClosed(stream)) {
2155 throw new FS.ErrnoError(8)
2156 }
2157 if ((stream.flags & 2097155) === 0) {
2158 throw new FS.ErrnoError(8)
2159 }
2160 if (FS.isDir(stream.node.mode)) {
2161 throw new FS.ErrnoError(31)
2162 }
2163 if (!stream.stream_ops.write) {
2164 throw new FS.ErrnoError(28)
2165 }
2166 if (stream.seekable && stream.flags & 1024) {
2167 FS.llseek(stream, 0, 2)
2168 }
2169 var seeking = typeof position != "undefined";
2170 if (!seeking) {
2171 position = stream.position
2172 } else if (!stream.seekable) {
2173 throw new FS.ErrnoError(70)
2174 }
2175 var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
2176 if (!seeking) stream.position += bytesWritten;
2177 return bytesWritten
2178 },
2179 allocate(stream, offset, length) {
2180 if (FS.isClosed(stream)) {
2181 throw new FS.ErrnoError(8)
2182 }
2183 if (offset < 0 || length <= 0) {
2184 throw new FS.ErrnoError(28)
2185 }
2186 if ((stream.flags & 2097155) === 0) {
2187 throw new FS.ErrnoError(8)
2188 }
2189 if (!FS.isFile(stream.node.mode) && !FS.isDir(stream.node.mode)) {
2190 throw new FS.ErrnoError(43)
2191 }
2192 if (!stream.stream_ops.allocate) {
2193 throw new FS.ErrnoError(138)
2194 }
2195 stream.stream_ops.allocate(stream, offset, length)
2196 },
2197 mmap(stream, length, position, prot, flags) {
2198 if ((prot & 2) !== 0 && (flags & 2) === 0 && (stream.flags & 2097155) !== 2) {
2199 throw new FS.ErrnoError(2)
2200 }
2201 if ((stream.flags & 2097155) === 1) {
2202 throw new FS.ErrnoError(2)
2203 }
2204 if (!stream.stream_ops.mmap) {
2205 throw new FS.ErrnoError(43)
2206 }
2207 return stream.stream_ops.mmap(stream, length, position, prot, flags)
2208 },
2209 msync(stream, buffer, offset, length, mmapFlags) {
2210 if (!stream.stream_ops.msync) {
2211 return 0
2212 }
2213 return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags)
2214 },
2215 munmap: stream => 0,
2216 ioctl(stream, cmd, arg) {
2217 if (!stream.stream_ops.ioctl) {
2218 throw new FS.ErrnoError(59)
2219 }
2220 return stream.stream_ops.ioctl(stream, cmd, arg)
2221 },
2222 readFile(path, opts = {}) {
2223 opts.flags = opts.flags || 0;
2224 opts.encoding = opts.encoding || "binary";
2225 if (opts.encoding !== "utf8" && opts.encoding !== "binary") {
2226 throw new Error(`Invalid encoding type "${opts.encoding}"`)
2227 }
2228 var ret;
2229 var stream = FS.open(path, opts.flags);
2230 var stat = FS.stat(path);
2231 var length = stat.size;
2232 var buf = new Uint8Array(length);
2233 FS.read(stream, buf, 0, length, 0);
2234 if (opts.encoding === "utf8") {
2235 ret = UTF8ArrayToString(buf, 0)
2236 } else if (opts.encoding === "binary") {
2237 ret = buf
2238 }
2239 FS.close(stream);
2240 return ret
2241 },
2242 writeFile(path, data, opts = {}) {
2243 opts.flags = opts.flags || 577;
2244 var stream = FS.open(path, opts.flags, opts.mode);
2245 if (typeof data == "string") {
2246 var buf = new Uint8Array(lengthBytesUTF8(data) + 1);
2247 var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
2248 FS.write(stream, buf, 0, actualNumBytes, undefined, opts.canOwn)
2249 } else if (ArrayBuffer.isView(data)) {
2250 FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn)
2251 } else {
2252 throw new Error("Unsupported data type")
2253 }
2254 FS.close(stream)
2255 },
2256 cwd: () => FS.currentPath,
2257 chdir(path) {
2258 var lookup = FS.lookupPath(path, {
2259 follow: true
2260 });
2261 if (lookup.node === null) {
2262 throw new FS.ErrnoError(44)
2263 }
2264 if (!FS.isDir(lookup.node.mode)) {
2265 throw new FS.ErrnoError(54)
2266 }
2267 var errCode = FS.nodePermissions(lookup.node, "x");
2268 if (errCode) {
2269 throw new FS.ErrnoError(errCode)
2270 }
2271 FS.currentPath = lookup.path
2272 },
2273 createDefaultDirectories() {
2274 FS.mkdir("/tmp");
2275 FS.mkdir("/home");
2276 FS.mkdir("/home/web_user")
2277 },
2278 createDefaultDevices() {
2279 FS.mkdir("/dev");
2280 FS.registerDevice(FS.makedev(1, 3), {
2281 read: () => 0,
2282 write: (stream, buffer, offset, length, pos) => length
2283 });
2284 FS.mkdev("/dev/null", FS.makedev(1, 3));
2285 TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
2286 TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
2287 FS.mkdev("/dev/tty", FS.makedev(5, 0));
2288 FS.mkdev("/dev/tty1", FS.makedev(6, 0));
2289 var randomBuffer = new Uint8Array(1024),
2290 randomLeft = 0;
2291 var randomByte = () => {
2292 if (randomLeft === 0) {
2293 randomLeft = randomFill(randomBuffer).byteLength
2294 }
2295 return randomBuffer[--randomLeft]
2296 };
2297 FS.createDevice("/dev", "random", randomByte);
2298 FS.createDevice("/dev", "urandom", randomByte);
2299 FS.mkdir("/dev/shm");
2300 FS.mkdir("/dev/shm/tmp")
2301 },
2302 createSpecialDirectories() {
2303 FS.mkdir("/proc");
2304 var proc_self = FS.mkdir("/proc/self");
2305 FS.mkdir("/proc/self/fd");
2306 FS.mount({
2307 mount() {
2308 var node = FS.createNode(proc_self, "fd", 16384 | 511, 73);
2309 node.node_ops = {
2310 lookup(parent, name) {
2311 var fd = +name;
2312 var stream = FS.getStreamChecked(fd);
2313 var ret = {
2314 parent: null,
2315 mount: {
2316 mountpoint: "fake"
2317 },
2318 node_ops: {
2319 readlink: () => stream.path
2320 }
2321 };
2322 ret.parent = ret;
2323 return ret
2324 }
2325 };
2326 return node
2327 }
2328 }, {}, "/proc/self/fd")
2329 },
2330 createStandardStreams() {
2331 if (Module["stdin"]) {
2332 FS.createDevice("/dev", "stdin", Module["stdin"])
2333 } else {
2334 FS.symlink("/dev/tty", "/dev/stdin")
2335 }
2336 if (Module["stdout"]) {
2337 FS.createDevice("/dev", "stdout", null, Module["stdout"])
2338 } else {
2339 FS.symlink("/dev/tty", "/dev/stdout")
2340 }
2341 if (Module["stderr"]) {
2342 FS.createDevice("/dev", "stderr", null, Module["stderr"])
2343 } else {
2344 FS.symlink("/dev/tty1", "/dev/stderr")
2345 }
2346 var stdin = FS.open("/dev/stdin", 0);
2347 var stdout = FS.open("/dev/stdout", 1);
2348 var stderr = FS.open("/dev/stderr", 1)
2349 },
2350 staticInit() {
2351 [44].forEach(code => {
2352 FS.genericErrors[code] = new FS.ErrnoError(code);
2353 FS.genericErrors[code].stack = "<generic error, no stack>"
2354 });
2355 FS.nameTable = new Array(4096);
2356 FS.mount(MEMFS, {}, "/");
2357 FS.createDefaultDirectories();
2358 FS.createDefaultDevices();
2359 FS.createSpecialDirectories();
2360 FS.filesystems = {
2361 "MEMFS": MEMFS
2362 }
2363 },
2364 init(input, output, error) {
2365 FS.init.initialized = true;
2366 Module["stdin"] = input || Module["stdin"];
2367 Module["stdout"] = output || Module["stdout"];
2368 Module["stderr"] = error || Module["stderr"];
2369 FS.createStandardStreams()
2370 },
2371 quit() {
2372 FS.init.initialized = false;
2373 for (var i = 0; i < FS.streams.length; i++) {
2374 var stream = FS.streams[i];
2375 if (!stream) {
2376 continue
2377 }
2378 FS.close(stream)
2379 }
2380 },
2381 findObject(path, dontResolveLastLink) {
2382 var ret = FS.analyzePath(path, dontResolveLastLink);
2383 if (!ret.exists) {
2384 return null
2385 }
2386 return ret.object
2387 },
2388 analyzePath(path, dontResolveLastLink) {
2389 try {
2390 var lookup = FS.lookupPath(path, {
2391 follow: !dontResolveLastLink
2392 });
2393 path = lookup.path
2394 } catch (e) {}
2395 var ret = {
2396 isRoot: false,
2397 exists: false,
2398 error: 0,
2399 name: null,
2400 path: null,
2401 object: null,
2402 parentExists: false,
2403 parentPath: null,
2404 parentObject: null
2405 };
2406 try {
2407 var lookup = FS.lookupPath(path, {
2408 parent: true
2409 });
2410 ret.parentExists = true;
2411 ret.parentPath = lookup.path;
2412 ret.parentObject = lookup.node;
2413 ret.name = PATH.basename(path);
2414 lookup = FS.lookupPath(path, {
2415 follow: !dontResolveLastLink
2416 });
2417 ret.exists = true;
2418 ret.path = lookup.path;
2419 ret.object = lookup.node;
2420 ret.name = lookup.node.name;
2421 ret.isRoot = lookup.path === "/"
2422 } catch (e) {
2423 ret.error = e.errno
2424 }
2425 return ret
2426 },
2427 createPath(parent, path, canRead, canWrite) {
2428 parent = typeof parent == "string" ? parent : FS.getPath(parent);
2429 var parts = path.split("/").reverse();
2430 while (parts.length) {
2431 var part = parts.pop();
2432 if (!part) continue;
2433 var current = PATH.join2(parent, part);
2434 try {
2435 FS.mkdir(current)
2436 } catch (e) {}
2437 parent = current
2438 }
2439 return current
2440 },
2441 createFile(parent, name, properties, canRead, canWrite) {
2442 var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2443 var mode = FS_getMode(canRead, canWrite);
2444 return FS.create(path, mode)
2445 },
2446 createDataFile(parent, name, data, canRead, canWrite, canOwn) {
2447 var path = name;
2448 if (parent) {
2449 parent = typeof parent == "string" ? parent : FS.getPath(parent);
2450 path = name ? PATH.join2(parent, name) : parent
2451 }
2452 var mode = FS_getMode(canRead, canWrite);
2453 var node = FS.create(path, mode);
2454 if (data) {
2455 if (typeof data == "string") {
2456 var arr = new Array(data.length);
2457 for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
2458 data = arr
2459 }
2460 FS.chmod(node, mode | 146);
2461 var stream = FS.open(node, 577);
2462 FS.write(stream, data, 0, data.length, 0, canOwn);
2463 FS.close(stream);
2464 FS.chmod(node, mode)
2465 }
2466 },
2467 createDevice(parent, name, input, output) {
2468 var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2469 var mode = FS_getMode(!!input, !!output);
2470 if (!FS.createDevice.major) FS.createDevice.major = 64;
2471 var dev = FS.makedev(FS.createDevice.major++, 0);
2472 FS.registerDevice(dev, {
2473 open(stream) {
2474 stream.seekable = false
2475 },
2476 close(stream) {
2477 if (output?.buffer?.length) {
2478 output(10)
2479 }
2480 },
2481 read(stream, buffer, offset, length, pos) {
2482 var bytesRead = 0;
2483 for (var i = 0; i < length; i++) {
2484 var result;
2485 try {
2486 result = input()
2487 } catch (e) {
2488 throw new FS.ErrnoError(29)
2489 }
2490 if (result === undefined && bytesRead === 0) {
2491 throw new FS.ErrnoError(6)
2492 }
2493 if (result === null || result === undefined) break;
2494 bytesRead++;
2495 buffer[offset + i] = result
2496 }
2497 if (bytesRead) {
2498 stream.node.timestamp = Date.now()
2499 }
2500 return bytesRead
2501 },
2502 write(stream, buffer, offset, length, pos) {
2503 for (var i = 0; i < length; i++) {
2504 try {
2505 output(buffer[offset + i])
2506 } catch (e) {
2507 throw new FS.ErrnoError(29)
2508 }
2509 }
2510 if (length) {
2511 stream.node.timestamp = Date.now()
2512 }
2513 return i
2514 }
2515 });
2516 return FS.mkdev(path, mode, dev)
2517 },
2518 forceLoadFile(obj) {
2519 if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
2520 if (typeof XMLHttpRequest != "undefined") {
2521 throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.")
2522 } else if (read_) {
2523 try {
2524 obj.contents = intArrayFromString(read_(obj.url), true);
2525 obj.usedBytes = obj.contents.length
2526 } catch (e) {
2527 throw new FS.ErrnoError(29)
2528 }
2529 } else {
2530 throw new Error("Cannot load without read() or XMLHttpRequest.")
2531 }
2532 },
2533 createLazyFile(parent, name, url, canRead, canWrite) {
2534 function LazyUint8Array() {
2535 this.lengthKnown = false;
2536 this.chunks = []
2537 }
2538 LazyUint8Array.prototype.get = function LazyUint8Array_get(idx) {
2539 if (idx > this.length - 1 || idx < 0) {
2540 return undefined
2541 }
2542 var chunkOffset = idx % this.chunkSize;
2543 var chunkNum = idx / this.chunkSize | 0;
2544 return this.getter(chunkNum)[chunkOffset]
2545 };
2546 LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
2547 this.getter = getter
2548 };
2549 LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
2550 var xhr = new XMLHttpRequest;
2551 xhr.open("HEAD", url, false);
2552 xhr.send(null);
2553 if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
2554 var datalength = Number(xhr.getResponseHeader("Content-length"));
2555 var header;
2556 var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
2557 var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
2558 var chunkSize = 1024 * 1024;
2559 if (!hasByteServing) chunkSize = datalength;
2560 var doXHR = (from, to) => {
2561 if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
2562 if (to > datalength - 1) throw new Error("only " + datalength + " bytes available! programmer error!");
2563 var xhr = new XMLHttpRequest;
2564 xhr.open("GET", url, false);
2565 if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
2566 xhr.responseType = "arraybuffer";
2567 if (xhr.overrideMimeType) {
2568 xhr.overrideMimeType("text/plain; charset=x-user-defined")
2569 }
2570 xhr.send(null);
2571 if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
2572 if (xhr.response !== undefined) {
2573 return new Uint8Array(xhr.response || [])
2574 }
2575 return intArrayFromString(xhr.responseText || "", true)
2576 };
2577 var lazyArray = this;
2578 lazyArray.setDataGetter(chunkNum => {
2579 var start = chunkNum * chunkSize;
2580 var end = (chunkNum + 1) * chunkSize - 1;
2581 end = Math.min(end, datalength - 1);
2582 if (typeof lazyArray.chunks[chunkNum] == "undefined") {
2583 lazyArray.chunks[chunkNum] = doXHR(start, end)
2584 }
2585 if (typeof lazyArray.chunks[chunkNum] == "undefined") throw new Error("doXHR failed!");
2586 return lazyArray.chunks[chunkNum]
2587 });
2588 if (usesGzip || !datalength) {
2589 chunkSize = datalength = 1;
2590 datalength = this.getter(0).length;
2591 chunkSize = datalength;
2592 out("LazyFiles on gzip forces download of the whole file when length is accessed")
2593 }
2594 this._length = datalength;
2595 this._chunkSize = chunkSize;
2596 this.lengthKnown = true
2597 };
2598 if (typeof XMLHttpRequest != "undefined") {
2599 if (!ENVIRONMENT_IS_WORKER) throw "Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";
2600 var lazyArray = new LazyUint8Array;
2601 Object.defineProperties(lazyArray, {
2602 length: {
2603 get: function() {
2604 if (!this.lengthKnown) {
2605 this.cacheLength()
2606 }
2607 return this._length
2608 }
2609 },
2610 chunkSize: {
2611 get: function() {
2612 if (!this.lengthKnown) {
2613 this.cacheLength()
2614 }
2615 return this._chunkSize
2616 }
2617 }
2618 });
2619 var properties = {
2620 isDevice: false,
2621 contents: lazyArray
2622 }
2623 } else {
2624 var properties = {
2625 isDevice: false,
2626 url: url
2627 }
2628 }
2629 var node = FS.createFile(parent, name, properties, canRead, canWrite);
2630 if (properties.contents) {
2631 node.contents = properties.contents
2632 } else if (properties.url) {
2633 node.contents = null;
2634 node.url = properties.url
2635 }
2636 Object.defineProperties(node, {
2637 usedBytes: {
2638 get: function() {
2639 return this.contents.length
2640 }
2641 }
2642 });
2643 var stream_ops = {};
2644 var keys = Object.keys(node.stream_ops);
2645 keys.forEach(key => {
2646 var fn = node.stream_ops[key];
2647 stream_ops[key] = (...args) => {
2648 FS.forceLoadFile(node);
2649 return fn(...args)
2650 }
2651 });
2652
2653 function writeChunks(stream, buffer, offset, length, position) {
2654 var contents = stream.node.contents;
2655 if (position >= contents.length) return 0;
2656 var size = Math.min(contents.length - position, length);
2657 if (contents.slice) {
2658 for (var i = 0; i < size; i++) {
2659 buffer[offset + i] = contents[position + i]
2660 }
2661 } else {
2662 for (var i = 0; i < size; i++) {
2663 buffer[offset + i] = contents.get(position + i)
2664 }
2665 }
2666 return size
2667 }
2668 stream_ops.read = (stream, buffer, offset, length, position) => {
2669 FS.forceLoadFile(node);
2670 return writeChunks(stream, buffer, offset, length, position)
2671 };
2672 stream_ops.mmap = (stream, length, position, prot, flags) => {
2673 FS.forceLoadFile(node);
2674 var ptr = mmapAlloc(length);
2675 if (!ptr) {
2676 throw new FS.ErrnoError(48)
2677 }
2678 writeChunks(stream, HEAP8, ptr, length, position);
2679 return {
2680 ptr: ptr,
2681 allocated: true
2682 }
2683 };
2684 node.stream_ops = stream_ops;
2685 return node
2686 }
2687 };
2688 var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
2689 var SYSCALLS = {
2690 DEFAULT_POLLMASK: 5,
2691 calculateAt(dirfd, path, allowEmpty) {
2692 if (PATH.isAbs(path)) {
2693 return path
2694 }
2695 var dir;
2696 if (dirfd === -100) {
2697 dir = FS.cwd()
2698 } else {
2699 var dirstream = SYSCALLS.getStreamFromFD(dirfd);
2700 dir = dirstream.path
2701 }
2702 if (path.length == 0) {
2703 if (!allowEmpty) {
2704 throw new FS.ErrnoError(44)
2705 }
2706 return dir
2707 }
2708 return PATH.join2(dir, path)
2709 },
2710 doStat(func, path, buf) {
2711 var stat = func(path);
2712 HEAP32[buf >> 2] = stat.dev;
2713 HEAP32[buf + 4 >> 2] = stat.mode;
2714 HEAPU32[buf + 8 >> 2] = stat.nlink;
2715 HEAP32[buf + 12 >> 2] = stat.uid;
2716 HEAP32[buf + 16 >> 2] = stat.gid;
2717 HEAP32[buf + 20 >> 2] = stat.rdev;
2718 tempI64 = [stat.size >>> 0, (tempDouble = stat.size, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[buf + 24 >> 2] = tempI64[0], HEAP32[buf + 28 >> 2] = tempI64[1];
2719 HEAP32[buf + 32 >> 2] = 4096;
2720 HEAP32[buf + 36 >> 2] = stat.blocks;
2721 var atime = stat.atime.getTime();
2722 var mtime = stat.mtime.getTime();
2723 var ctime = stat.ctime.getTime();
2724 tempI64 = [Math.floor(atime / 1e3) >>> 0, (tempDouble = Math.floor(atime / 1e3), +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[buf + 40 >> 2] = tempI64[0], HEAP32[buf + 44 >> 2] = tempI64[1];
2725 HEAPU32[buf + 48 >> 2] = atime % 1e3 * 1e3;
2726 tempI64 = [Math.floor(mtime / 1e3) >>> 0, (tempDouble = Math.floor(mtime / 1e3), +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[buf + 56 >> 2] = tempI64[0], HEAP32[buf + 60 >> 2] = tempI64[1];
2727 HEAPU32[buf + 64 >> 2] = mtime % 1e3 * 1e3;
2728 tempI64 = [Math.floor(ctime / 1e3) >>> 0, (tempDouble = Math.floor(ctime / 1e3), +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[buf + 72 >> 2] = tempI64[0], HEAP32[buf + 76 >> 2] = tempI64[1];
2729 HEAPU32[buf + 80 >> 2] = ctime % 1e3 * 1e3;
2730 tempI64 = [stat.ino >>> 0, (tempDouble = stat.ino, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[buf + 88 >> 2] = tempI64[0], HEAP32[buf + 92 >> 2] = tempI64[1];
2731 return 0
2732 },
2733 doMsync(addr, stream, len, flags, offset) {
2734 if (!FS.isFile(stream.node.mode)) {
2735 throw new FS.ErrnoError(43)
2736 }
2737 if (flags & 2) {
2738 return 0
2739 }
2740 var buffer = HEAPU8.slice(addr, addr + len);
2741 FS.msync(stream, buffer, offset, len, flags)
2742 },
2743 varargs: undefined,
2744 get() {
2745 var ret = HEAP32[+SYSCALLS.varargs >> 2];
2746 SYSCALLS.varargs += 4;
2747 return ret
2748 },
2749 getp() {
2750 return SYSCALLS.get()
2751 },
2752 getStr(ptr) {
2753 var ret = UTF8ToString(ptr);
2754 return ret
2755 },
2756 getStreamFromFD(fd) {
2757 var stream = FS.getStreamChecked(fd);
2758 return stream
2759 }
2760 };
2761
2762 function ___syscall_fcntl64(fd, cmd, varargs) {
2763 SYSCALLS.varargs = varargs;
2764 try {
2765 var stream = SYSCALLS.getStreamFromFD(fd);
2766 switch (cmd) {
2767 case 0: {
2768 var arg = SYSCALLS.get();
2769 if (arg < 0) {
2770 return -28
2771 }
2772 while (FS.streams[arg]) {
2773 arg++
2774 }
2775 var newStream;
2776 newStream = FS.createStream(stream, arg);
2777 return newStream.fd
2778 }
2779 case 1:
2780 case 2:
2781 return 0;
2782 case 3:
2783 return stream.flags;
2784 case 4: {
2785 var arg = SYSCALLS.get();
2786 stream.flags |= arg;
2787 return 0
2788 }
2789 case 12: {
2790 var arg = SYSCALLS.getp();
2791 var offset = 0;
2792 HEAP16[arg + offset >> 1] = 2;
2793 return 0
2794 }
2795 case 13:
2796 case 14:
2797 return 0
2798 }
2799 return -28
2800 } catch (e) {
2801 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
2802 return -e.errno
2803 }
2804 }
2805
2806 function ___syscall_ioctl(fd, op, varargs) {
2807 SYSCALLS.varargs = varargs;
2808 try {
2809 var stream = SYSCALLS.getStreamFromFD(fd);
2810 switch (op) {
2811 case 21509: {
2812 if (!stream.tty) return -59;
2813 return 0
2814 }
2815 case 21505: {
2816 if (!stream.tty) return -59;
2817 if (stream.tty.ops.ioctl_tcgets) {
2818 var termios = stream.tty.ops.ioctl_tcgets(stream);
2819 var argp = SYSCALLS.getp();
2820 HEAP32[argp >> 2] = termios.c_iflag || 0;
2821 HEAP32[argp + 4 >> 2] = termios.c_oflag || 0;
2822 HEAP32[argp + 8 >> 2] = termios.c_cflag || 0;
2823 HEAP32[argp + 12 >> 2] = termios.c_lflag || 0;
2824 for (var i = 0; i < 32; i++) {
2825 HEAP8[argp + i + 17] = termios.c_cc[i] || 0
2826 }
2827 return 0
2828 }
2829 return 0
2830 }
2831 case 21510:
2832 case 21511:
2833 case 21512: {
2834 if (!stream.tty) return -59;
2835 return 0
2836 }
2837 case 21506:
2838 case 21507:
2839 case 21508: {
2840 if (!stream.tty) return -59;
2841 if (stream.tty.ops.ioctl_tcsets) {
2842 var argp = SYSCALLS.getp();
2843 var c_iflag = HEAP32[argp >> 2];
2844 var c_oflag = HEAP32[argp + 4 >> 2];
2845 var c_cflag = HEAP32[argp + 8 >> 2];
2846 var c_lflag = HEAP32[argp + 12 >> 2];
2847 var c_cc = [];
2848 for (var i = 0; i < 32; i++) {
2849 c_cc.push(HEAP8[argp + i + 17])
2850 }
2851 return stream.tty.ops.ioctl_tcsets(stream.tty, op, {
2852 c_iflag: c_iflag,
2853 c_oflag: c_oflag,
2854 c_cflag: c_cflag,
2855 c_lflag: c_lflag,
2856 c_cc: c_cc
2857 })
2858 }
2859 return 0
2860 }
2861 case 21519: {
2862 if (!stream.tty) return -59;
2863 var argp = SYSCALLS.getp();
2864 HEAP32[argp >> 2] = 0;
2865 return 0
2866 }
2867 case 21520: {
2868 if (!stream.tty) return -59;
2869 return -28
2870 }
2871 case 21531: {
2872 var argp = SYSCALLS.getp();
2873 return FS.ioctl(stream, op, argp)
2874 }
2875 case 21523: {
2876 if (!stream.tty) return -59;
2877 if (stream.tty.ops.ioctl_tiocgwinsz) {
2878 var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
2879 var argp = SYSCALLS.getp();
2880 HEAP16[argp >> 1] = winsize[0];
2881 HEAP16[argp + 2 >> 1] = winsize[1]
2882 }
2883 return 0
2884 }
2885 case 21524: {
2886 if (!stream.tty) return -59;
2887 return 0
2888 }
2889 case 21515: {
2890 if (!stream.tty) return -59;
2891 return 0
2892 }
2893 default:
2894 return -28
2895 }
2896 } catch (e) {
2897 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
2898 return -e.errno
2899 }
2900 }
2901
2902 function ___syscall_openat(dirfd, path, flags, varargs) {
2903 SYSCALLS.varargs = varargs;
2904 try {
2905 path = SYSCALLS.getStr(path);
2906 path = SYSCALLS.calculateAt(dirfd, path);
2907 var mode = varargs ? SYSCALLS.get() : 0;
2908 return FS.open(path, flags, mode).fd
2909 } catch (e) {
2910 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
2911 return -e.errno
2912 }
2913 }
2914
2915 function ___syscall_stat64(path, buf) {
2916 try {
2917 path = SYSCALLS.getStr(path);
2918 return SYSCALLS.doStat(FS.stat, path, buf)
2919 } catch (e) {
2920 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
2921 return -e.errno
2922 }
2923 }
2924 var _emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
2925 var abortOnCannotGrowMemory = requestedSize => {
2926 abort("OOM")
2927 };
2928 var _emscripten_resize_heap = requestedSize => {
2929 var oldSize = HEAPU8.length;
2930 requestedSize >>>= 0;
2931 abortOnCannotGrowMemory(requestedSize)
2932 };
2933 var ENV = {};
2934 var getExecutableName = () => thisProgram || "./this.program";
2935 var getEnvStrings = () => {
2936 if (!getEnvStrings.strings) {
2937 var lang = (typeof navigator == "object" && navigator.languages && navigator.languages[0] || "C").replace("-", "_") + ".UTF-8";
2938 var env = {
2939 "USER": "web_user",
2940 "LOGNAME": "web_user",
2941 "PATH": "/",
2942 "PWD": "/",
2943 "HOME": "/home/web_user",
2944 "LANG": lang,
2945 "_": getExecutableName()
2946 };
2947 for (var x in ENV) {
2948 if (ENV[x] === undefined) delete env[x];
2949 else env[x] = ENV[x]
2950 }
2951 var strings = [];
2952 for (var x in env) {
2953 strings.push(`${x}=${env[x]}`)
2954 }
2955 getEnvStrings.strings = strings
2956 }
2957 return getEnvStrings.strings
2958 };
2959 var stringToAscii = (str, buffer) => {
2960 for (var i = 0; i < str.length; ++i) {
2961 HEAP8[buffer++] = str.charCodeAt(i)
2962 }
2963 HEAP8[buffer] = 0
2964 };
2965 var _environ_get = (__environ, environ_buf) => {
2966 var bufSize = 0;
2967 getEnvStrings().forEach((string, i) => {
2968 var ptr = environ_buf + bufSize;
2969 HEAPU32[__environ + i * 4 >> 2] = ptr;
2970 stringToAscii(string, ptr);
2971 bufSize += string.length + 1
2972 });
2973 return 0
2974 };
2975 var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
2976 var strings = getEnvStrings();
2977 HEAPU32[penviron_count >> 2] = strings.length;
2978 var bufSize = 0;
2979 strings.forEach(string => bufSize += string.length + 1);
2980 HEAPU32[penviron_buf_size >> 2] = bufSize;
2981 return 0
2982 };
2983 var runtimeKeepaliveCounter = 0;
2984 var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
2985 var _proc_exit = code => {
2986 EXITSTATUS = code;
2987 if (!keepRuntimeAlive()) {
2988 Module["onExit"]?.(code);
2989 ABORT = true
2990 }
2991 quit_(code, new ExitStatus(code))
2992 };
2993 var exitJS = (status, implicit) => {
2994 EXITSTATUS = status;
2995 _proc_exit(status)
2996 };
2997 var _exit = exitJS;
2998
2999 function _fd_close(fd) {
3000 try {
3001 var stream = SYSCALLS.getStreamFromFD(fd);
3002 FS.close(stream);
3003 return 0
3004 } catch (e) {
3005 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3006 return e.errno
3007 }
3008 }
3009
3010 function _fd_fdstat_get(fd, pbuf) {
3011 try {
3012 var rightsBase = 0;
3013 var rightsInheriting = 0;
3014 var flags = 0;
3015 {
3016 var stream = SYSCALLS.getStreamFromFD(fd);
3017 var type = stream.tty ? 2 : FS.isDir(stream.mode) ? 3 : FS.isLink(stream.mode) ? 7 : 4
3018 }
3019 HEAP8[pbuf] = type;
3020 HEAP16[pbuf + 2 >> 1] = flags;
3021 tempI64 = [rightsBase >>> 0, (tempDouble = rightsBase, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[pbuf + 8 >> 2] = tempI64[0], HEAP32[pbuf + 12 >> 2] = tempI64[1];
3022 tempI64 = [rightsInheriting >>> 0, (tempDouble = rightsInheriting, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[pbuf + 16 >> 2] = tempI64[0], HEAP32[pbuf + 20 >> 2] = tempI64[1];
3023 return 0
3024 } catch (e) {
3025 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3026 return e.errno
3027 }
3028 }
3029 var doReadv = (stream, iov, iovcnt, offset) => {
3030 var ret = 0;
3031 for (var i = 0; i < iovcnt; i++) {
3032 var ptr = HEAPU32[iov >> 2];
3033 var len = HEAPU32[iov + 4 >> 2];
3034 iov += 8;
3035 var curr = FS.read(stream, HEAP8, ptr, len, offset);
3036 if (curr < 0) return -1;
3037 ret += curr;
3038 if (curr < len) break;
3039 if (typeof offset !== "undefined") {
3040 offset += curr
3041 }
3042 }
3043 return ret
3044 };
3045
3046 function _fd_read(fd, iov, iovcnt, pnum) {
3047 try {
3048 var stream = SYSCALLS.getStreamFromFD(fd);
3049 var num = doReadv(stream, iov, iovcnt);
3050 HEAPU32[pnum >> 2] = num;
3051 return 0
3052 } catch (e) {
3053 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3054 return e.errno
3055 }
3056 }
3057 var convertI32PairToI53Checked = (lo, hi) => hi + 2097152 >>> 0 < 4194305 - !!lo ? (lo >>> 0) + hi * 4294967296 : NaN;
3058
3059 function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
3060 var offset = convertI32PairToI53Checked(offset_low, offset_high);
3061 try {
3062 if (isNaN(offset)) return 61;
3063 var stream = SYSCALLS.getStreamFromFD(fd);
3064 FS.llseek(stream, offset, whence);
3065 tempI64 = [stream.position >>> 0, (tempDouble = stream.position, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? +Math.floor(tempDouble / 4294967296) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[newOffset >> 2] = tempI64[0], HEAP32[newOffset + 4 >> 2] = tempI64[1];
3066 if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null;
3067 return 0
3068 } catch (e) {
3069 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3070 return e.errno
3071 }
3072 }
3073 var doWritev = (stream, iov, iovcnt, offset) => {
3074 var ret = 0;
3075 for (var i = 0; i < iovcnt; i++) {
3076 var ptr = HEAPU32[iov >> 2];
3077 var len = HEAPU32[iov + 4 >> 2];
3078 iov += 8;
3079 var curr = FS.write(stream, HEAP8, ptr, len, offset);
3080 if (curr < 0) return -1;
3081 ret += curr;
3082 if (typeof offset !== "undefined") {
3083 offset += curr
3084 }
3085 }
3086 return ret
3087 };
3088
3089 function _fd_write(fd, iov, iovcnt, pnum) {
3090 try {
3091 var stream = SYSCALLS.getStreamFromFD(fd);
3092 var num = doWritev(stream, iov, iovcnt);
3093 HEAPU32[pnum >> 2] = num;
3094 return 0
3095 } catch (e) {
3096 if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
3097 return e.errno
3098 }
3099 }
3100 var runAndAbortIfError = func => {
3101 try {
3102 return func()
3103 } catch (e) {
3104 abort(e)
3105 }
3106 };
3107 var handleException = e => {
3108 if (e instanceof ExitStatus || e == "unwind") {
3109 return EXITSTATUS
3110 }
3111 quit_(1, e)
3112 };
3113 var maybeExit = () => {
3114 if (!keepRuntimeAlive()) {
3115 try {
3116 _exit(EXITSTATUS)
3117 } catch (e) {
3118 handleException(e)
3119 }
3120 }
3121 };
3122 var callUserCallback = func => {
3123 if (ABORT) {
3124 return
3125 }
3126 try {
3127 func();
3128 maybeExit()
3129 } catch (e) {
3130 handleException(e)
3131 }
3132 };
3133 var runtimeKeepalivePush = () => {
3134 runtimeKeepaliveCounter += 1
3135 };
3136 var runtimeKeepalivePop = () => {
3137 runtimeKeepaliveCounter -= 1
3138 };
3139 var Asyncify = {
3140 instrumentWasmImports(imports) {
3141 var importPattern = /^(invoke_.*|__asyncjs__.*)$/;
3142 for (let [x, original] of Object.entries(imports)) {
3143 let sig = original.sig;
3144 if (typeof original == "function") {
3145 let isAsyncifyImport = original.isAsync || importPattern.test(x)
3146 }
3147 }
3148 },
3149 instrumentWasmExports(exports) {
3150 var ret = {};
3151 for (let [x, original] of Object.entries(exports)) {
3152 if (typeof original == "function") {
3153 ret[x] = (...args) => {
3154 Asyncify.exportCallStack.push(x);
3155 try {
3156 return original(...args)
3157 } finally {
3158 if (!ABORT) {
3159 var y = Asyncify.exportCallStack.pop();
3160 Asyncify.maybeStopUnwind()
3161 }
3162 }
3163 }
3164 } else {
3165 ret[x] = original
3166 }
3167 }
3168 return ret
3169 },
3170 State: {
3171 Normal: 0,
3172 Unwinding: 1,
3173 Rewinding: 2,
3174 Disabled: 3
3175 },
3176 state: 0,
3177 StackSize: 4096,
3178 currData: null,
3179 handleSleepReturnValue: 0,
3180 exportCallStack: [],
3181 callStackNameToId: {},
3182 callStackIdToName: {},
3183 callStackId: 0,
3184 asyncPromiseHandlers: null,
3185 sleepCallbacks: [],
3186 getCallStackId(funcName) {
3187 var id = Asyncify.callStackNameToId[funcName];
3188 if (id === undefined) {
3189 id = Asyncify.callStackId++;
3190 Asyncify.callStackNameToId[funcName] = id;
3191 Asyncify.callStackIdToName[id] = funcName
3192 }
3193 return id
3194 },
3195 maybeStopUnwind() {
3196 if (Asyncify.currData && Asyncify.state === Asyncify.State.Unwinding && Asyncify.exportCallStack.length === 0) {
3197 Asyncify.state = Asyncify.State.Normal;
3198 runAndAbortIfError(_asyncify_stop_unwind);
3199 if (typeof Fibers != "undefined") {
3200 Fibers.trampoline()
3201 }
3202 }
3203 },
3204 whenDone() {
3205 return new Promise((resolve, reject) => {
3206 Asyncify.asyncPromiseHandlers = {
3207 resolve: resolve,
3208 reject: reject
3209 }
3210 })
3211 },
3212 allocateData() {
3213 var ptr = _malloc(12 + Asyncify.StackSize);
3214 Asyncify.setDataHeader(ptr, ptr + 12, Asyncify.StackSize);
3215 Asyncify.setDataRewindFunc(ptr);
3216 return ptr
3217 },
3218 setDataHeader(ptr, stack, stackSize) {
3219 HEAPU32[ptr >> 2] = stack;
3220 HEAPU32[ptr + 4 >> 2] = stack + stackSize
3221 },
3222 setDataRewindFunc(ptr) {
3223 var bottomOfCallStack = Asyncify.exportCallStack[0];
3224 var rewindId = Asyncify.getCallStackId(bottomOfCallStack);
3225 HEAP32[ptr + 8 >> 2] = rewindId
3226 },
3227 getDataRewindFunc(ptr) {
3228 var id = HEAP32[ptr + 8 >> 2];
3229 var name = Asyncify.callStackIdToName[id];
3230 var func = wasmExports[name];
3231 return func
3232 },
3233 doRewind(ptr) {
3234 var start = Asyncify.getDataRewindFunc(ptr);
3235 return start()
3236 },
3237 handleSleep(startAsync) {
3238 if (ABORT) return;
3239 if (Asyncify.state === Asyncify.State.Normal) {
3240 var reachedCallback = false;
3241 var reachedAfterCallback = false;
3242 startAsync((handleSleepReturnValue = 0) => {
3243 if (ABORT) return;
3244 Asyncify.handleSleepReturnValue = handleSleepReturnValue;
3245 reachedCallback = true;
3246 if (!reachedAfterCallback) {
3247 return
3248 }
3249 Asyncify.state = Asyncify.State.Rewinding;
3250 runAndAbortIfError(() => _asyncify_start_rewind(Asyncify.currData));
3251 if (typeof Browser != "undefined" && Browser.mainLoop.func) {
3252 Browser.mainLoop.resume()
3253 }
3254 var asyncWasmReturnValue, isError = false;
3255 try {
3256 asyncWasmReturnValue = Asyncify.doRewind(Asyncify.currData)
3257 } catch (err) {
3258 asyncWasmReturnValue = err;
3259 isError = true
3260 }
3261 var handled = false;
3262 if (!Asyncify.currData) {
3263 var asyncPromiseHandlers = Asyncify.asyncPromiseHandlers;
3264 if (asyncPromiseHandlers) {
3265 Asyncify.asyncPromiseHandlers = null;
3266 (isError ? asyncPromiseHandlers.reject : asyncPromiseHandlers.resolve)(asyncWasmReturnValue);
3267 handled = true
3268 }
3269 }
3270 if (isError && !handled) {
3271 throw asyncWasmReturnValue
3272 }
3273 });
3274 reachedAfterCallback = true;
3275 if (!reachedCallback) {
3276 Asyncify.state = Asyncify.State.Unwinding;
3277 Asyncify.currData = Asyncify.allocateData();
3278 if (typeof Browser != "undefined" && Browser.mainLoop.func) {
3279 Browser.mainLoop.pause()
3280 }
3281 runAndAbortIfError(() => _asyncify_start_unwind(Asyncify.currData))
3282 }
3283 } else if (Asyncify.state === Asyncify.State.Rewinding) {
3284 Asyncify.state = Asyncify.State.Normal;
3285 runAndAbortIfError(_asyncify_stop_rewind);
3286 _free(Asyncify.currData);
3287 Asyncify.currData = null;
3288 Asyncify.sleepCallbacks.forEach(callUserCallback)
3289 } else {
3290 abort(`invalid state: ${Asyncify.state}`)
3291 }
3292 return Asyncify.handleSleepReturnValue
3293 },
3294 handleAsync(startAsync) {
3295 return Asyncify.handleSleep(wakeUp => {
3296 startAsync().then(wakeUp)
3297 })
3298 }
3299 };
3300 var getCFunc = ident => {
3301 var func = Module["_" + ident];
3302 return func
3303 };
3304 var writeArrayToMemory = (array, buffer) => {
3305 HEAP8.set(array, buffer)
3306 };
3307 var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
3308 var stringToUTF8OnStack = str => {
3309 var size = lengthBytesUTF8(str) + 1;
3310 var ret = stackAlloc(size);
3311 stringToUTF8(str, ret, size);
3312 return ret
3313 };
3314 var ccall = (ident, returnType, argTypes, args, opts) => {
3315 var toC = {
3316 "string": str => {
3317 var ret = 0;
3318 if (str !== null && str !== undefined && str !== 0) {
3319 ret = stringToUTF8OnStack(str)
3320 }
3321 return ret
3322 },
3323 "array": arr => {
3324 var ret = stackAlloc(arr.length);
3325 writeArrayToMemory(arr, ret);
3326 return ret
3327 }
3328 };
3329
3330 function convertReturnValue(ret) {
3331 if (returnType === "string") {
3332 return UTF8ToString(ret)
3333 }
3334 if (returnType === "boolean") return Boolean(ret);
3335 return ret
3336 }
3337 var func = getCFunc(ident);
3338 var cArgs = [];
3339 var stack = 0;
3340 if (args) {
3341 for (var i = 0; i < args.length; i++) {
3342 var converter = toC[argTypes[i]];
3343 if (converter) {
3344 if (stack === 0) stack = stackSave();
3345 cArgs[i] = converter(args[i])
3346 } else {
3347 cArgs[i] = args[i]
3348 }
3349 }
3350 }
3351 var previousAsync = Asyncify.currData;
3352 var ret = func(...cArgs);
3353
3354 function onDone(ret) {
3355 runtimeKeepalivePop();
3356 if (stack !== 0) stackRestore(stack);
3357 return convertReturnValue(ret)
3358 }
3359 var asyncMode = opts?.async;
3360 runtimeKeepalivePush();
3361 if (Asyncify.currData != previousAsync) {
3362 return Asyncify.whenDone().then(onDone)
3363 }
3364 ret = onDone(ret);
3365 if (asyncMode) return Promise.resolve(ret);
3366 return ret
3367 };
3368 var cwrap = (ident, returnType, argTypes, opts) => {
3369 var numericArgs = !argTypes || argTypes.every(type => type === "number" || type === "boolean");
3370 var numericRet = returnType !== "string";
3371 if (numericRet && numericArgs && !opts) {
3372 return getCFunc(ident)
3373 }
3374 return (...args) => ccall(ident, returnType, argTypes, args, opts)
3375 };
3376 var stringToNewUTF8 = str => {
3377 var size = lengthBytesUTF8(str) + 1;
3378 var ret = _malloc(size);
3379 if (ret) stringToUTF8(str, ret, size);
3380 return ret
3381 };
3382 var FSNode = function(parent, name, mode, rdev) {
3383 if (!parent) {
3384 parent = this
3385 }
3386 this.parent = parent;
3387 this.mount = parent.mount;
3388 this.mounted = null;
3389 this.id = FS.nextInode++;
3390 this.name = name;
3391 this.mode = mode;
3392 this.node_ops = {};
3393 this.stream_ops = {};
3394 this.rdev = rdev
3395 };
3396 var readMode = 292 | 73;
3397 var writeMode = 146;
3398 Object.defineProperties(FSNode.prototype, {
3399 read: {
3400 get: function() {
3401 return (this.mode & readMode) === readMode
3402 },
3403 set: function(val) {
3404 val ? this.mode |= readMode : this.mode &= ~readMode
3405 }
3406 },
3407 write: {
3408 get: function() {
3409 return (this.mode & writeMode) === writeMode
3410 },
3411 set: function(val) {
3412 val ? this.mode |= writeMode : this.mode &= ~writeMode
3413 }
3414 },
3415 isFolder: {
3416 get: function() {
3417 return FS.isDir(this.mode)
3418 }
3419 },
3420 isDevice: {
3421 get: function() {
3422 return FS.isChrdev(this.mode)
3423 }
3424 }
3425 });
3426 FS.FSNode = FSNode;
3427 FS.createPreloadedFile = FS_createPreloadedFile;
3428 FS.staticInit();
3429 Module["FS_createPath"] = FS.createPath;
3430 Module["FS_createDataFile"] = FS.createDataFile;
3431 Module["FS_createPreloadedFile"] = FS.createPreloadedFile;
3432 Module["FS_unlink"] = FS.unlink;
3433 Module["FS_createLazyFile"] = FS.createLazyFile;
3434 Module["FS_createDevice"] = FS.createDevice;
3435 var wasmImports = {
3436 d: ___syscall_fcntl64,
3437 h: ___syscall_ioctl,
3438 i: ___syscall_openat,
3439 l: ___syscall_stat64,
3440 n: _emscripten_memcpy_js,
3441 k: _emscripten_resize_heap,
3442 e: _environ_get,
3443 f: _environ_sizes_get,
3444 a: _exit,
3445 b: _fd_close,
3446 m: _fd_fdstat_get,
3447 g: _fd_read,
3448 j: _fd_seek,
3449 c: _fd_write
3450 };
3451 var wasmExports = createWasm();
3452 var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports["p"])();
3453 var _free = a0 => (_free = wasmExports["q"])(a0);
3454 var _malloc = a0 => (_malloc = wasmExports["r"])(a0);
3455 var _test_int = Module["_test_int"] = (a0, a1) => (_test_int = Module["_test_int"] = wasmExports["t"])(a0, a1);
3456 var _do_a_conversion = Module["_do_a_conversion"] = (a0, a1) => (_do_a_conversion = Module["_do_a_conversion"] = wasmExports["u"])(a0, a1);
3457 var stackSave = () => (stackSave = wasmExports["v"])();
3458 var stackRestore = a0 => (stackRestore = wasmExports["w"])(a0);
3459 var stackAlloc = a0 => (stackAlloc = wasmExports["x"])(a0);
3460 var _asyncify_start_unwind = a0 => (_asyncify_start_unwind = wasmExports["y"])(a0);
3461 var _asyncify_stop_unwind = () => (_asyncify_stop_unwind = wasmExports["z"])();
3462 var _asyncify_start_rewind = a0 => (_asyncify_start_rewind = wasmExports["A"])(a0);
3463 var _asyncify_stop_rewind = () => (_asyncify_stop_rewind = wasmExports["B"])();
3464 Module["addRunDependency"] = addRunDependency;
3465 Module["removeRunDependency"] = removeRunDependency;
3466 Module["FS_createPath"] = FS.createPath;
3467 Module["FS_createLazyFile"] = FS.createLazyFile;
3468 Module["FS_createDevice"] = FS.createDevice;
3469 Module["ccall"] = ccall;
3470 Module["cwrap"] = cwrap;
3471 Module["stringToNewUTF8"] = stringToNewUTF8;
3472 Module["FS_createPreloadedFile"] = FS.createPreloadedFile;
3473 Module["FS_createDataFile"] = FS.createDataFile;
3474 Module["FS_unlink"] = FS.unlink;
3475 var calledRun;
3476 dependenciesFulfilled = function runCaller() {
3477 if (!calledRun) run();
3478 if (!calledRun) dependenciesFulfilled = runCaller
3479 };
3480
3481 function run() {
3482 if (runDependencies > 0) {
3483 return
3484 }
3485 preRun();
3486 if (runDependencies > 0) {
3487 return
3488 }
3489
3490 function doRun() {
3491 if (calledRun) return;
3492 calledRun = true;
3493 Module["calledRun"] = true;
3494 if (ABORT) return;
3495 initRuntime();
3496 readyPromiseResolve(Module);
3497 if (Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"]();
3498 postRun()
3499 }
3500 if (Module["setStatus"]) {
3501 Module["setStatus"]("Running...");
3502 setTimeout(function() {
3503 setTimeout(function() {
3504 Module["setStatus"]("")
3505 }, 1);
3506 doRun()
3507 }, 1)
3508 } else {
3509 doRun()
3510 }
3511 }
3512 if (Module["preInit"]) {
3513 if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
3514 while (Module["preInit"].length > 0) {
3515 Module["preInit"].pop()()
3516 }
3517 }
3518 run();
3519 return moduleArg.ready
3520 }
3521 );
3522})();
3523if (typeof exports === 'object' && typeof module === 'object')
3524 module.exports = createMyModule;
3525else if (typeof define === 'function' && define['amd'])
3526 define([], () => createMyModule);