@gen3/workspaces 0.12.64 → 0.12.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/jupyterlite-builds/free-private/jupyter_lite_config.json +5 -19
- package/dist/jupyterlite-builds/free-private/requirements.txt +1 -1
- package/dist/jupyterlite-builds/scripts/build-gen3sdk-lite.sh +428 -0
- package/dist/jupyterlite-builds/scripts/build-jupyterlite.sh +150 -33
- package/dist/jupyterlite-builds/scripts/setup-env.sh +81 -0
- package/dist/jupyterlite-builds/scripts/sync-jupyter-assets-into-package.sh +19 -2
- package/dist/jupyterlite-builds/scripts/validate-jupyterlite-assets.sh +3 -0
- package/jupyterlite-builds/free-private/jupyter_lite_config.json +5 -19
- package/jupyterlite-builds/free-private/requirements.txt +1 -1
- package/package.json +7 -4
- package/scripts/build-gen3sdk-lite.sh +428 -0
- package/scripts/build-jupyterlite.sh +150 -33
- package/scripts/patch-pyidode-lock.py +100 -0
- package/scripts/setup-env.sh +81 -0
- package/scripts/sync-jupyter-assets-into-package.sh +19 -2
- package/scripts/validate-jupyterlite-assets.sh +3 -0
- package/dist/jupyterlite-builds/scripts/build-gen3sdk-lite_v2.sh +0 -310
- package/dist/jupyterlite-builds/scripts/build-jupyterlite_v2.sh +0 -111
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/aiofiles-25.1.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/backoff-2.2.1-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/cdislogging-1.2.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/comm-0.2.3-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/dataclasses_json-0.5.9-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/dictionaryutils-4.0.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/drsclient-0.4.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/fastavro-1.12.2-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3-4.28.3-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3dictionary-3.0.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/gen3users-1.1.1-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/humanfriendly-10.0-py2.py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/importlib_metadata-8.9.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/indexclient-6.3.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/ipykernel-6.9.2-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/ipython_pygments_lexers-1.1.1-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/marshmallow-3.26.2-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/marshmallow_enum-1.5.1-py2.py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/mypy_extensions-1.1.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/piplite-0.8.5-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pyodide_http-0.2.2-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pyodide_kernel-0.8.5-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/pypfb-0.6.2-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/python_json_logger-4.2.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/typing_inspect-0.9.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/xmltodict-0.13.0-py2.py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_uv_wheels/zipp-4.1.0-py3-none-any.whl +0 -0
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/constraints.txt +0 -354
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/excludes.txt +0 -3
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/pylock.toml +0 -347
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/_work/requirements.in +0 -26
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/patched-pyodide-lock.json +0 -1
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/pyodide-lock.json +0 -1
- package/jupyterlite-builds/free-private/.cache/pyodide-lock/remote-pyodide-lock.json +0 -1
- package/jupyterlite-builds/free-private/.cache/wheels/aiofiles-25.1.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/backoff-2.2.1-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/cdislogging-1.2.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/dataclasses_json-0.5.9-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/dictionaryutils-4.0.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/drsclient-0.4.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/fastavro-1.12.2-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/gen3-4.28.3-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/gen3dictionary-3.0.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/gen3users-1.1.1-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/humanfriendly-10.0-py2.py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/importlib_metadata-8.9.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/indexclient-6.3.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/marshmallow-3.26.2-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/marshmallow_enum-1.5.1-py2.py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/mypy_extensions-1.1.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/pypfb-0.6.2-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/python_json_logger-4.2.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/typing_inspect-0.9.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/xmltodict-0.13.0-py2.py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/.cache/wheels/zipp-4.1.0-py3-none-any.whl.meta.json +0 -24
- package/jupyterlite-builds/free-private/cockle-config.json +0 -71
- package/jupyterlite-builds/free-private/cockle_wasm_env/.mambarc +0 -1
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/coreutils.js +0 -5421
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/coreutils.wasm +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.d.ts +0 -375
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.js +0 -3401
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/fs.wasm +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/grep.js +0 -3839
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/grep.wasm +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.data +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.js +0 -5060
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/less.wasm +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/sed.js +0 -3843
- package/jupyterlite-builds/free-private/cockle_wasm_env/bin/sed.wasm +0 -0
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/cockle_fs-0.3.0-h27506cd_2.json +0 -60
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/coreutils-9.10-h072c4ef_3.json +0 -52
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/emscripten-abi-4.0.9-h267e887_9.json +0 -31
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/grep-3.12-h8b79025_0.json +0 -52
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/history +0 -10
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/less-693-hf259948_0.json +0 -60
- package/jupyterlite-builds/free-private/cockle_wasm_env/conda-meta/sed-4.9-h072c4ef_0.json +0 -52
- package/scripts/aiohttp-3.13.5-cp314-cp314-pyemscripten_2026_0_wasm32.whl +0 -0
- package/scripts/build-gen3sdk-lite_v2.sh +0 -310
- package/scripts/build-jupyterlite_v2.sh +0 -111
|
@@ -1,3401 +0,0 @@
|
|
|
1
|
-
var Module = (() => {
|
|
2
|
-
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
|
|
3
|
-
return (
|
|
4
|
-
async function(moduleArg = {}) {
|
|
5
|
-
var moduleRtn;
|
|
6
|
-
|
|
7
|
-
// include: shell.js
|
|
8
|
-
// The Module object: Our interface to the outside world. We import
|
|
9
|
-
// and export values on it. There are various ways Module can be used:
|
|
10
|
-
// 1. Not defined. We create it here
|
|
11
|
-
// 2. A function parameter, function(moduleArg) => Promise<Module>
|
|
12
|
-
// 3. pre-run appended it, var Module = {}; ..generated code..
|
|
13
|
-
// 4. External script tag defines var Module.
|
|
14
|
-
// We need to check if Module already exists (e.g. case 3 above).
|
|
15
|
-
// Substitution will be replaced with actual code on later stage of the build,
|
|
16
|
-
// this way Closure Compiler will not mangle it (e.g. case 4. above).
|
|
17
|
-
// Note that if you want to run closure, and also to use Module
|
|
18
|
-
// after the generated code, you will need to define var Module = {};
|
|
19
|
-
// before the code. Then that object will be used in the code, and you
|
|
20
|
-
// can continue to use Module afterwards as well.
|
|
21
|
-
var Module = moduleArg;
|
|
22
|
-
|
|
23
|
-
// Set up the promise that indicates the Module is initialized
|
|
24
|
-
var readyPromiseResolve, readyPromiseReject;
|
|
25
|
-
|
|
26
|
-
var readyPromise = new Promise((resolve, reject) => {
|
|
27
|
-
readyPromiseResolve = resolve;
|
|
28
|
-
readyPromiseReject = reject;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Determine the runtime environment we are in. You can customize this by
|
|
32
|
-
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
33
|
-
// Attempt to auto-detect the environment
|
|
34
|
-
var ENVIRONMENT_IS_WEB = typeof window == "object";
|
|
35
|
-
|
|
36
|
-
var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
|
|
37
|
-
|
|
38
|
-
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
39
|
-
// also a web environment.
|
|
40
|
-
var ENVIRONMENT_IS_NODE = typeof process == "object" && process.versions?.node && process.type != "renderer";
|
|
41
|
-
|
|
42
|
-
if (ENVIRONMENT_IS_NODE) {}
|
|
43
|
-
|
|
44
|
-
// --pre-jses are emitted after the Module integration code, so that they can
|
|
45
|
-
// refer to Module (if they choose; they can also define Module)
|
|
46
|
-
var arguments_ = [];
|
|
47
|
-
|
|
48
|
-
var thisProgram = "./this.program";
|
|
49
|
-
|
|
50
|
-
var quit_ = (status, toThrow) => {
|
|
51
|
-
throw toThrow;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (typeof __filename != "undefined") {
|
|
55
|
-
// Node
|
|
56
|
-
_scriptName = __filename;
|
|
57
|
-
} else if (ENVIRONMENT_IS_WORKER) {
|
|
58
|
-
_scriptName = self.location.href;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// `/` should be present at the end if `scriptDirectory` is not empty
|
|
62
|
-
var scriptDirectory = "";
|
|
63
|
-
|
|
64
|
-
function locateFile(path) {
|
|
65
|
-
if (Module["locateFile"]) {
|
|
66
|
-
return Module["locateFile"](path, scriptDirectory);
|
|
67
|
-
}
|
|
68
|
-
return scriptDirectory + path;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Hooks that are implemented differently in different runtime environments.
|
|
72
|
-
var readAsync, readBinary;
|
|
73
|
-
|
|
74
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
75
|
-
// These modules will usually be used on Node.js. Load them eagerly to avoid
|
|
76
|
-
// the complexity of lazy-loading.
|
|
77
|
-
var fs = require("fs");
|
|
78
|
-
var nodePath = require("path");
|
|
79
|
-
scriptDirectory = __dirname + "/";
|
|
80
|
-
// include: node_shell_read.js
|
|
81
|
-
readBinary = filename => {
|
|
82
|
-
// We need to re-wrap `file://` strings to URLs.
|
|
83
|
-
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
84
|
-
var ret = fs.readFileSync(filename);
|
|
85
|
-
return ret;
|
|
86
|
-
};
|
|
87
|
-
readAsync = async (filename, binary = true) => {
|
|
88
|
-
// See the comment in the `readBinary` function.
|
|
89
|
-
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
90
|
-
var ret = fs.readFileSync(filename, binary ? undefined : "utf8");
|
|
91
|
-
return ret;
|
|
92
|
-
};
|
|
93
|
-
// end include: node_shell_read.js
|
|
94
|
-
if (process.argv.length > 1) {
|
|
95
|
-
thisProgram = process.argv[1].replace(/\\/g, "/");
|
|
96
|
-
}
|
|
97
|
-
arguments_ = process.argv.slice(2);
|
|
98
|
-
quit_ = (status, toThrow) => {
|
|
99
|
-
process.exitCode = status;
|
|
100
|
-
throw toThrow;
|
|
101
|
-
};
|
|
102
|
-
} else // Note that this includes Node.js workers when relevant (pthreads is enabled).
|
|
103
|
-
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
|
|
104
|
-
// ENVIRONMENT_IS_NODE.
|
|
105
|
-
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
|
106
|
-
try {
|
|
107
|
-
scriptDirectory = new URL(".", _scriptName).href;
|
|
108
|
-
} catch {}
|
|
109
|
-
{
|
|
110
|
-
// include: web_or_worker_shell_read.js
|
|
111
|
-
if (ENVIRONMENT_IS_WORKER) {
|
|
112
|
-
readBinary = url => {
|
|
113
|
-
var xhr = new XMLHttpRequest;
|
|
114
|
-
xhr.open("GET", url, false);
|
|
115
|
-
xhr.responseType = "arraybuffer";
|
|
116
|
-
xhr.send(null);
|
|
117
|
-
return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response));
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
readAsync = async url => {
|
|
121
|
-
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
|
122
|
-
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
123
|
-
// Cordova or Electron apps are typically loaded from a file:// url.
|
|
124
|
-
// So use XHR on webview if URL is a file URL.
|
|
125
|
-
if (isFileURI(url)) {
|
|
126
|
-
return new Promise((resolve, reject) => {
|
|
127
|
-
var xhr = new XMLHttpRequest;
|
|
128
|
-
xhr.open("GET", url, true);
|
|
129
|
-
xhr.responseType = "arraybuffer";
|
|
130
|
-
xhr.onload = () => {
|
|
131
|
-
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
|
|
132
|
-
// file URLs can return 0
|
|
133
|
-
resolve(xhr.response);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
reject(xhr.status);
|
|
137
|
-
};
|
|
138
|
-
xhr.onerror = reject;
|
|
139
|
-
xhr.send(null);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
var response = await fetch(url, {
|
|
143
|
-
credentials: "same-origin"
|
|
144
|
-
});
|
|
145
|
-
if (response.ok) {
|
|
146
|
-
return response.arrayBuffer();
|
|
147
|
-
}
|
|
148
|
-
throw new Error(response.status + " : " + response.url);
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
} else {}
|
|
152
|
-
|
|
153
|
-
var out = console.log.bind(console);
|
|
154
|
-
|
|
155
|
-
var err = console.error.bind(console);
|
|
156
|
-
|
|
157
|
-
// end include: shell.js
|
|
158
|
-
// include: preamble.js
|
|
159
|
-
// === Preamble library stuff ===
|
|
160
|
-
// Documentation for the public APIs defined in this file must be updated in:
|
|
161
|
-
// site/source/docs/api_reference/preamble.js.rst
|
|
162
|
-
// A prebuilt local version of the documentation is available at:
|
|
163
|
-
// site/build/text/docs/api_reference/preamble.js.txt
|
|
164
|
-
// You can also build docs locally as HTML or other formats in site/
|
|
165
|
-
// An online HTML version (which may be of a different version of Emscripten)
|
|
166
|
-
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
167
|
-
var wasmBinary;
|
|
168
|
-
|
|
169
|
-
// Wasm globals
|
|
170
|
-
var wasmMemory;
|
|
171
|
-
|
|
172
|
-
//========================================
|
|
173
|
-
// Runtime essentials
|
|
174
|
-
//========================================
|
|
175
|
-
// whether we are quitting the application. no code should run after this.
|
|
176
|
-
// set in exit() and abort()
|
|
177
|
-
var ABORT = false;
|
|
178
|
-
|
|
179
|
-
// Memory management
|
|
180
|
-
var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /* BigInt64Array type is not correctly defined in closure
|
|
181
|
-
/** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure
|
|
182
|
-
/** not-t@type {!BigUint64Array} */ HEAPU64, /** @type {!Float64Array} */ HEAPF64;
|
|
183
|
-
|
|
184
|
-
var runtimeInitialized = false;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
|
|
188
|
-
* @noinline
|
|
189
|
-
*/ var isFileURI = filename => filename.startsWith("file://");
|
|
190
|
-
|
|
191
|
-
// include: runtime_shared.js
|
|
192
|
-
// include: runtime_stack_check.js
|
|
193
|
-
// end include: runtime_stack_check.js
|
|
194
|
-
// include: runtime_exceptions.js
|
|
195
|
-
// end include: runtime_exceptions.js
|
|
196
|
-
// include: runtime_debug.js
|
|
197
|
-
// end include: runtime_debug.js
|
|
198
|
-
// include: memoryprofiler.js
|
|
199
|
-
// end include: memoryprofiler.js
|
|
200
|
-
function updateMemoryViews() {
|
|
201
|
-
var b = wasmMemory.buffer;
|
|
202
|
-
HEAP8 = new Int8Array(b);
|
|
203
|
-
HEAP16 = new Int16Array(b);
|
|
204
|
-
HEAPU8 = new Uint8Array(b);
|
|
205
|
-
HEAPU16 = new Uint16Array(b);
|
|
206
|
-
HEAP32 = new Int32Array(b);
|
|
207
|
-
HEAPU32 = new Uint32Array(b);
|
|
208
|
-
HEAPF32 = new Float32Array(b);
|
|
209
|
-
HEAPF64 = new Float64Array(b);
|
|
210
|
-
HEAP64 = new BigInt64Array(b);
|
|
211
|
-
HEAPU64 = new BigUint64Array(b);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// end include: runtime_shared.js
|
|
215
|
-
function preRun() {
|
|
216
|
-
if (Module["preRun"]) {
|
|
217
|
-
if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
|
|
218
|
-
while (Module["preRun"].length) {
|
|
219
|
-
addOnPreRun(Module["preRun"].shift());
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
// Begin ATPRERUNS hooks
|
|
223
|
-
callRuntimeCallbacks(onPreRuns);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function initRuntime() {
|
|
227
|
-
runtimeInitialized = true;
|
|
228
|
-
// Begin ATINITS hooks
|
|
229
|
-
if (!Module["noFSInit"] && !FS.initialized) FS.init();
|
|
230
|
-
TTY.init();
|
|
231
|
-
// End ATINITS hooks
|
|
232
|
-
wasmExports["__wasm_call_ctors"]();
|
|
233
|
-
// Begin ATPOSTCTORS hooks
|
|
234
|
-
FS.ignorePermissions = false;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function postRun() {
|
|
238
|
-
// PThreads reuse the runtime from the main thread.
|
|
239
|
-
if (Module["postRun"]) {
|
|
240
|
-
if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
|
|
241
|
-
while (Module["postRun"].length) {
|
|
242
|
-
addOnPostRun(Module["postRun"].shift());
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
// Begin ATPOSTRUNS hooks
|
|
246
|
-
callRuntimeCallbacks(onPostRuns);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// A counter of dependencies for calling run(). If we need to
|
|
250
|
-
// do asynchronous work before running, increment this and
|
|
251
|
-
// decrement it. Incrementing must happen in a place like
|
|
252
|
-
// Module.preRun (used by emcc to add file preloading).
|
|
253
|
-
// Note that you can add dependencies in preRun, even though
|
|
254
|
-
// it happens right before run - run will be postponed until
|
|
255
|
-
// the dependencies are met.
|
|
256
|
-
var runDependencies = 0;
|
|
257
|
-
|
|
258
|
-
var dependenciesFulfilled = null;
|
|
259
|
-
|
|
260
|
-
// overridden to take different actions when all run dependencies are fulfilled
|
|
261
|
-
function getUniqueRunDependency(id) {
|
|
262
|
-
return id;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function addRunDependency(id) {
|
|
266
|
-
runDependencies++;
|
|
267
|
-
Module["monitorRunDependencies"]?.(runDependencies);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function removeRunDependency(id) {
|
|
271
|
-
runDependencies--;
|
|
272
|
-
Module["monitorRunDependencies"]?.(runDependencies);
|
|
273
|
-
if (runDependencies == 0) {
|
|
274
|
-
if (dependenciesFulfilled) {
|
|
275
|
-
var callback = dependenciesFulfilled;
|
|
276
|
-
dependenciesFulfilled = null;
|
|
277
|
-
callback();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/** @param {string|number=} what */ function abort(what) {
|
|
283
|
-
Module["onAbort"]?.(what);
|
|
284
|
-
what = "Aborted(" + what + ")";
|
|
285
|
-
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|
286
|
-
// catches the exception?
|
|
287
|
-
err(what);
|
|
288
|
-
ABORT = true;
|
|
289
|
-
what += ". Build with -sASSERTIONS for more info.";
|
|
290
|
-
// Use a wasm runtime error, because a JS error might be seen as a foreign
|
|
291
|
-
// exception, which means we'd run destructors on it. We need the error to
|
|
292
|
-
// simply make the program stop.
|
|
293
|
-
// FIXME This approach does not work in Wasm EH because it currently does not assume
|
|
294
|
-
// all RuntimeErrors are from traps; it decides whether a RuntimeError is from
|
|
295
|
-
// a trap or not based on a hidden field within the object. So at the moment
|
|
296
|
-
// we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
|
|
297
|
-
// allows this in the wasm spec.
|
|
298
|
-
// Suppress closure compiler warning here. Closure compiler's builtin extern
|
|
299
|
-
// definition for WebAssembly.RuntimeError claims it takes no arguments even
|
|
300
|
-
// though it can.
|
|
301
|
-
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
|
|
302
|
-
// See above, in the meantime, we resort to wasm code for trapping.
|
|
303
|
-
// In case abort() is called before the module is initialized, wasmExports
|
|
304
|
-
// and its exported '__trap' function is not available, in which case we throw
|
|
305
|
-
// a RuntimeError.
|
|
306
|
-
// We trap instead of throwing RuntimeError to prevent infinite-looping in
|
|
307
|
-
// Wasm EH code (because RuntimeError is considered as a foreign exception and
|
|
308
|
-
// caught by 'catch_all'), but in case throwing RuntimeError is fine because
|
|
309
|
-
// the module has not even been instantiated, even less running.
|
|
310
|
-
if (runtimeInitialized) {
|
|
311
|
-
___trap();
|
|
312
|
-
}
|
|
313
|
-
/** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
|
|
314
|
-
readyPromiseReject(e);
|
|
315
|
-
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
316
|
-
// in code paths apart from instantiation where an exception is expected
|
|
317
|
-
// to be thrown when abort is called.
|
|
318
|
-
throw e;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
var wasmBinaryFile;
|
|
322
|
-
|
|
323
|
-
function findWasmBinary() {
|
|
324
|
-
return locateFile("fs.wasm");
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function getBinarySync(file) {
|
|
328
|
-
if (file == wasmBinaryFile && wasmBinary) {
|
|
329
|
-
return new Uint8Array(wasmBinary);
|
|
330
|
-
}
|
|
331
|
-
if (readBinary) {
|
|
332
|
-
return readBinary(file);
|
|
333
|
-
}
|
|
334
|
-
throw "both async and sync fetching of the wasm failed";
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async function getWasmBinary(binaryFile) {
|
|
338
|
-
// If we don't have the binary yet, load it asynchronously using readAsync.
|
|
339
|
-
if (!wasmBinary) {
|
|
340
|
-
// Fetch the binary using readAsync
|
|
341
|
-
try {
|
|
342
|
-
var response = await readAsync(binaryFile);
|
|
343
|
-
return new Uint8Array(response);
|
|
344
|
-
} catch {}
|
|
345
|
-
}
|
|
346
|
-
// Otherwise, getBinarySync should be able to get it synchronously
|
|
347
|
-
return getBinarySync(binaryFile);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
async function instantiateArrayBuffer(binaryFile, imports) {
|
|
351
|
-
try {
|
|
352
|
-
var binary = await getWasmBinary(binaryFile);
|
|
353
|
-
var instance = await WebAssembly.instantiate(binary, imports);
|
|
354
|
-
return instance;
|
|
355
|
-
} catch (reason) {
|
|
356
|
-
err(`failed to asynchronously prepare wasm: ${reason}`);
|
|
357
|
-
abort(reason);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async function instantiateAsync(binary, binaryFile, imports) {
|
|
362
|
-
if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) {
|
|
363
|
-
try {
|
|
364
|
-
var response = fetch(binaryFile, {
|
|
365
|
-
credentials: "same-origin"
|
|
366
|
-
});
|
|
367
|
-
var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
|
|
368
|
-
return instantiationResult;
|
|
369
|
-
} catch (reason) {
|
|
370
|
-
// We expect the most common failure cause to be a bad MIME type for the binary,
|
|
371
|
-
// in which case falling back to ArrayBuffer instantiation should work.
|
|
372
|
-
err(`wasm streaming compile failed: ${reason}`);
|
|
373
|
-
err("falling back to ArrayBuffer instantiation");
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return instantiateArrayBuffer(binaryFile, imports);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function getWasmImports() {
|
|
380
|
-
// prepare imports
|
|
381
|
-
return {
|
|
382
|
-
"env": wasmImports,
|
|
383
|
-
"wasi_snapshot_preview1": wasmImports
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Create the wasm instance.
|
|
388
|
-
// Receives the wasm imports, returns the exports.
|
|
389
|
-
async function createWasm() {
|
|
390
|
-
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
391
|
-
// handle a generated wasm instance, receiving its exports and
|
|
392
|
-
// performing other necessary setup
|
|
393
|
-
/** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
|
|
394
|
-
wasmExports = instance.exports;
|
|
395
|
-
wasmMemory = wasmExports["memory"];
|
|
396
|
-
updateMemoryViews();
|
|
397
|
-
removeRunDependency("wasm-instantiate");
|
|
398
|
-
return wasmExports;
|
|
399
|
-
}
|
|
400
|
-
// wait for the pthread pool (if any)
|
|
401
|
-
addRunDependency("wasm-instantiate");
|
|
402
|
-
// Prefer streaming instantiation if available.
|
|
403
|
-
function receiveInstantiationResult(result) {
|
|
404
|
-
// 'result' is a ResultObject object which has both the module and instance.
|
|
405
|
-
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
|
|
406
|
-
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
|
|
407
|
-
// When the regression is fixed, can restore the above PTHREADS-enabled path.
|
|
408
|
-
return receiveInstance(result["instance"]);
|
|
409
|
-
}
|
|
410
|
-
var info = getWasmImports();
|
|
411
|
-
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
|
|
412
|
-
// to manually instantiate the Wasm module themselves. This allows pages to
|
|
413
|
-
// run the instantiation parallel to any other async startup actions they are
|
|
414
|
-
// performing.
|
|
415
|
-
// Also pthreads and wasm workers initialize the wasm instance through this
|
|
416
|
-
// path.
|
|
417
|
-
if (Module["instantiateWasm"]) {
|
|
418
|
-
return new Promise((resolve, reject) => {
|
|
419
|
-
Module["instantiateWasm"](info, (mod, inst) => {
|
|
420
|
-
resolve(receiveInstance(mod, inst));
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
wasmBinaryFile ??= findWasmBinary();
|
|
425
|
-
try {
|
|
426
|
-
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
|
|
427
|
-
var exports = receiveInstantiationResult(result);
|
|
428
|
-
return exports;
|
|
429
|
-
} catch (e) {
|
|
430
|
-
// If instantiation fails, reject the module ready promise.
|
|
431
|
-
readyPromiseReject(e);
|
|
432
|
-
return Promise.reject(e);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// end include: preamble.js
|
|
437
|
-
// Begin JS library code
|
|
438
|
-
class ExitStatus {
|
|
439
|
-
name="ExitStatus";
|
|
440
|
-
constructor(status) {
|
|
441
|
-
this.message = `Program terminated with exit(${status})`;
|
|
442
|
-
this.status = status;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
var callRuntimeCallbacks = callbacks => {
|
|
447
|
-
while (callbacks.length > 0) {
|
|
448
|
-
// Pass the module as the first argument.
|
|
449
|
-
callbacks.shift()(Module);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
var onPostRuns = [];
|
|
454
|
-
|
|
455
|
-
var addOnPostRun = cb => onPostRuns.push(cb);
|
|
456
|
-
|
|
457
|
-
var onPreRuns = [];
|
|
458
|
-
|
|
459
|
-
var addOnPreRun = cb => onPreRuns.push(cb);
|
|
460
|
-
|
|
461
|
-
var noExitRuntime = true;
|
|
462
|
-
|
|
463
|
-
var initRandomFill = () => {
|
|
464
|
-
// This block is not needed on v19+ since crypto.getRandomValues is builtin
|
|
465
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
466
|
-
var nodeCrypto = require("crypto");
|
|
467
|
-
return view => nodeCrypto.randomFillSync(view);
|
|
468
|
-
}
|
|
469
|
-
return view => crypto.getRandomValues(view);
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
var randomFill = view => {
|
|
473
|
-
// Lazily init on the first invocation.
|
|
474
|
-
(randomFill = initRandomFill())(view);
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
var PATH = {
|
|
478
|
-
isAbs: path => path.charAt(0) === "/",
|
|
479
|
-
splitPath: filename => {
|
|
480
|
-
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
|
481
|
-
return splitPathRe.exec(filename).slice(1);
|
|
482
|
-
},
|
|
483
|
-
normalizeArray: (parts, allowAboveRoot) => {
|
|
484
|
-
// if the path tries to go above the root, `up` ends up > 0
|
|
485
|
-
var up = 0;
|
|
486
|
-
for (var i = parts.length - 1; i >= 0; i--) {
|
|
487
|
-
var last = parts[i];
|
|
488
|
-
if (last === ".") {
|
|
489
|
-
parts.splice(i, 1);
|
|
490
|
-
} else if (last === "..") {
|
|
491
|
-
parts.splice(i, 1);
|
|
492
|
-
up++;
|
|
493
|
-
} else if (up) {
|
|
494
|
-
parts.splice(i, 1);
|
|
495
|
-
up--;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
// if the path is allowed to go above the root, restore leading ..s
|
|
499
|
-
if (allowAboveRoot) {
|
|
500
|
-
for (;up; up--) {
|
|
501
|
-
parts.unshift("..");
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return parts;
|
|
505
|
-
},
|
|
506
|
-
normalize: path => {
|
|
507
|
-
var isAbsolute = PATH.isAbs(path), trailingSlash = path.slice(-1) === "/";
|
|
508
|
-
// Normalize the path
|
|
509
|
-
path = PATH.normalizeArray(path.split("/").filter(p => !!p), !isAbsolute).join("/");
|
|
510
|
-
if (!path && !isAbsolute) {
|
|
511
|
-
path = ".";
|
|
512
|
-
}
|
|
513
|
-
if (path && trailingSlash) {
|
|
514
|
-
path += "/";
|
|
515
|
-
}
|
|
516
|
-
return (isAbsolute ? "/" : "") + path;
|
|
517
|
-
},
|
|
518
|
-
dirname: path => {
|
|
519
|
-
var result = PATH.splitPath(path), root = result[0], dir = result[1];
|
|
520
|
-
if (!root && !dir) {
|
|
521
|
-
// No dirname whatsoever
|
|
522
|
-
return ".";
|
|
523
|
-
}
|
|
524
|
-
if (dir) {
|
|
525
|
-
// It has a dirname, strip trailing slash
|
|
526
|
-
dir = dir.slice(0, -1);
|
|
527
|
-
}
|
|
528
|
-
return root + dir;
|
|
529
|
-
},
|
|
530
|
-
basename: path => path && path.match(/([^\/]+|\/)\/*$/)[1],
|
|
531
|
-
join: (...paths) => PATH.normalize(paths.join("/")),
|
|
532
|
-
join2: (l, r) => PATH.normalize(l + "/" + r)
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
var PATH_FS = {
|
|
536
|
-
resolve: (...args) => {
|
|
537
|
-
var resolvedPath = "", resolvedAbsolute = false;
|
|
538
|
-
for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
539
|
-
var path = (i >= 0) ? args[i] : FS.cwd();
|
|
540
|
-
// Skip empty and invalid entries
|
|
541
|
-
if (typeof path != "string") {
|
|
542
|
-
throw new TypeError("Arguments to path.resolve must be strings");
|
|
543
|
-
} else if (!path) {
|
|
544
|
-
return "";
|
|
545
|
-
}
|
|
546
|
-
resolvedPath = path + "/" + resolvedPath;
|
|
547
|
-
resolvedAbsolute = PATH.isAbs(path);
|
|
548
|
-
}
|
|
549
|
-
// At this point the path should be resolved to a full absolute path, but
|
|
550
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
551
|
-
resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter(p => !!p), !resolvedAbsolute).join("/");
|
|
552
|
-
return ((resolvedAbsolute ? "/" : "") + resolvedPath) || ".";
|
|
553
|
-
},
|
|
554
|
-
relative: (from, to) => {
|
|
555
|
-
from = PATH_FS.resolve(from).slice(1);
|
|
556
|
-
to = PATH_FS.resolve(to).slice(1);
|
|
557
|
-
function trim(arr) {
|
|
558
|
-
var start = 0;
|
|
559
|
-
for (;start < arr.length; start++) {
|
|
560
|
-
if (arr[start] !== "") break;
|
|
561
|
-
}
|
|
562
|
-
var end = arr.length - 1;
|
|
563
|
-
for (;end >= 0; end--) {
|
|
564
|
-
if (arr[end] !== "") break;
|
|
565
|
-
}
|
|
566
|
-
if (start > end) return [];
|
|
567
|
-
return arr.slice(start, end - start + 1);
|
|
568
|
-
}
|
|
569
|
-
var fromParts = trim(from.split("/"));
|
|
570
|
-
var toParts = trim(to.split("/"));
|
|
571
|
-
var length = Math.min(fromParts.length, toParts.length);
|
|
572
|
-
var samePartsLength = length;
|
|
573
|
-
for (var i = 0; i < length; i++) {
|
|
574
|
-
if (fromParts[i] !== toParts[i]) {
|
|
575
|
-
samePartsLength = i;
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
var outputParts = [];
|
|
580
|
-
for (var i = samePartsLength; i < fromParts.length; i++) {
|
|
581
|
-
outputParts.push("..");
|
|
582
|
-
}
|
|
583
|
-
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
584
|
-
return outputParts.join("/");
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined;
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
592
|
-
* array that contains uint8 values, returns a copy of that string as a
|
|
593
|
-
* Javascript String object.
|
|
594
|
-
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
595
|
-
* @param {number=} idx
|
|
596
|
-
* @param {number=} maxBytesToRead
|
|
597
|
-
* @return {string}
|
|
598
|
-
*/ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
|
|
599
|
-
var endIdx = idx + maxBytesToRead;
|
|
600
|
-
var endPtr = idx;
|
|
601
|
-
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
602
|
-
// null terminator by itself. Also, use the length info to avoid running tiny
|
|
603
|
-
// strings through TextDecoder, since .subarray() allocates garbage.
|
|
604
|
-
// (As a tiny code save trick, compare endPtr against endIdx using a negation,
|
|
605
|
-
// so that undefined/NaN means Infinity)
|
|
606
|
-
while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
|
|
607
|
-
// When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
|
|
608
|
-
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
609
|
-
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
610
|
-
}
|
|
611
|
-
var str = "";
|
|
612
|
-
// If building with TextDecoder, we have already computed the string length
|
|
613
|
-
// above, so test loop end condition against that
|
|
614
|
-
while (idx < endPtr) {
|
|
615
|
-
// For UTF8 byte structure, see:
|
|
616
|
-
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
617
|
-
// https://www.ietf.org/rfc/rfc2279.txt
|
|
618
|
-
// https://tools.ietf.org/html/rfc3629
|
|
619
|
-
var u0 = heapOrArray[idx++];
|
|
620
|
-
if (!(u0 & 128)) {
|
|
621
|
-
str += String.fromCharCode(u0);
|
|
622
|
-
continue;
|
|
623
|
-
}
|
|
624
|
-
var u1 = heapOrArray[idx++] & 63;
|
|
625
|
-
if ((u0 & 224) == 192) {
|
|
626
|
-
str += String.fromCharCode(((u0 & 31) << 6) | u1);
|
|
627
|
-
continue;
|
|
628
|
-
}
|
|
629
|
-
var u2 = heapOrArray[idx++] & 63;
|
|
630
|
-
if ((u0 & 240) == 224) {
|
|
631
|
-
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
632
|
-
} else {
|
|
633
|
-
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
634
|
-
}
|
|
635
|
-
if (u0 < 65536) {
|
|
636
|
-
str += String.fromCharCode(u0);
|
|
637
|
-
} else {
|
|
638
|
-
var ch = u0 - 65536;
|
|
639
|
-
str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return str;
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
var FS_stdin_getChar_buffer = [];
|
|
646
|
-
|
|
647
|
-
var lengthBytesUTF8 = str => {
|
|
648
|
-
var len = 0;
|
|
649
|
-
for (var i = 0; i < str.length; ++i) {
|
|
650
|
-
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
651
|
-
// unit, not a Unicode code point of the character! So decode
|
|
652
|
-
// UTF16->UTF32->UTF8.
|
|
653
|
-
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
654
|
-
var c = str.charCodeAt(i);
|
|
655
|
-
// possibly a lead surrogate
|
|
656
|
-
if (c <= 127) {
|
|
657
|
-
len++;
|
|
658
|
-
} else if (c <= 2047) {
|
|
659
|
-
len += 2;
|
|
660
|
-
} else if (c >= 55296 && c <= 57343) {
|
|
661
|
-
len += 4;
|
|
662
|
-
++i;
|
|
663
|
-
} else {
|
|
664
|
-
len += 3;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return len;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
671
|
-
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
672
|
-
// undefined and false each don't write out any bytes.
|
|
673
|
-
if (!(maxBytesToWrite > 0)) return 0;
|
|
674
|
-
var startIdx = outIdx;
|
|
675
|
-
var endIdx = outIdx + maxBytesToWrite - 1;
|
|
676
|
-
// -1 for string null terminator.
|
|
677
|
-
for (var i = 0; i < str.length; ++i) {
|
|
678
|
-
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
679
|
-
// unit, not a Unicode code point of the character! So decode
|
|
680
|
-
// UTF16->UTF32->UTF8.
|
|
681
|
-
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
682
|
-
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
|
|
683
|
-
// and https://www.ietf.org/rfc/rfc2279.txt
|
|
684
|
-
// and https://tools.ietf.org/html/rfc3629
|
|
685
|
-
var u = str.charCodeAt(i);
|
|
686
|
-
// possibly a lead surrogate
|
|
687
|
-
if (u >= 55296 && u <= 57343) {
|
|
688
|
-
var u1 = str.charCodeAt(++i);
|
|
689
|
-
u = 65536 + ((u & 1023) << 10) | (u1 & 1023);
|
|
690
|
-
}
|
|
691
|
-
if (u <= 127) {
|
|
692
|
-
if (outIdx >= endIdx) break;
|
|
693
|
-
heap[outIdx++] = u;
|
|
694
|
-
} else if (u <= 2047) {
|
|
695
|
-
if (outIdx + 1 >= endIdx) break;
|
|
696
|
-
heap[outIdx++] = 192 | (u >> 6);
|
|
697
|
-
heap[outIdx++] = 128 | (u & 63);
|
|
698
|
-
} else if (u <= 65535) {
|
|
699
|
-
if (outIdx + 2 >= endIdx) break;
|
|
700
|
-
heap[outIdx++] = 224 | (u >> 12);
|
|
701
|
-
heap[outIdx++] = 128 | ((u >> 6) & 63);
|
|
702
|
-
heap[outIdx++] = 128 | (u & 63);
|
|
703
|
-
} else {
|
|
704
|
-
if (outIdx + 3 >= endIdx) break;
|
|
705
|
-
heap[outIdx++] = 240 | (u >> 18);
|
|
706
|
-
heap[outIdx++] = 128 | ((u >> 12) & 63);
|
|
707
|
-
heap[outIdx++] = 128 | ((u >> 6) & 63);
|
|
708
|
-
heap[outIdx++] = 128 | (u & 63);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
// Null-terminate the pointer to the buffer.
|
|
712
|
-
heap[outIdx] = 0;
|
|
713
|
-
return outIdx - startIdx;
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
/** @type {function(string, boolean=, number=)} */ var intArrayFromString = (stringy, dontAddNull, length) => {
|
|
717
|
-
var len = length > 0 ? length : lengthBytesUTF8(stringy) + 1;
|
|
718
|
-
var u8array = new Array(len);
|
|
719
|
-
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
|
|
720
|
-
if (dontAddNull) u8array.length = numBytesWritten;
|
|
721
|
-
return u8array;
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
var FS_stdin_getChar = () => {
|
|
725
|
-
if (!FS_stdin_getChar_buffer.length) {
|
|
726
|
-
var result = null;
|
|
727
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
728
|
-
// we will read data by chunks of BUFSIZE
|
|
729
|
-
var BUFSIZE = 256;
|
|
730
|
-
var buf = Buffer.alloc(BUFSIZE);
|
|
731
|
-
var bytesRead = 0;
|
|
732
|
-
// For some reason we must suppress a closure warning here, even though
|
|
733
|
-
// fd definitely exists on process.stdin, and is even the proper way to
|
|
734
|
-
// get the fd of stdin,
|
|
735
|
-
// https://github.com/nodejs/help/issues/2136#issuecomment-523649904
|
|
736
|
-
// This started to happen after moving this logic out of library_tty.js,
|
|
737
|
-
// so it is related to the surrounding code in some unclear manner.
|
|
738
|
-
/** @suppress {missingProperties} */ var fd = process.stdin.fd;
|
|
739
|
-
try {
|
|
740
|
-
bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
|
|
741
|
-
} catch (e) {
|
|
742
|
-
// Cross-platform differences: on Windows, reading EOF throws an
|
|
743
|
-
// exception, but on other OSes, reading EOF returns 0. Uniformize
|
|
744
|
-
// behavior by treating the EOF exception to return 0.
|
|
745
|
-
if (e.toString().includes("EOF")) bytesRead = 0; else throw e;
|
|
746
|
-
}
|
|
747
|
-
if (bytesRead > 0) {
|
|
748
|
-
result = buf.slice(0, bytesRead).toString("utf-8");
|
|
749
|
-
}
|
|
750
|
-
} else if (typeof window != "undefined" && typeof window.prompt == "function") {
|
|
751
|
-
// Browser.
|
|
752
|
-
result = window.prompt("Input: ");
|
|
753
|
-
// returns null on cancel
|
|
754
|
-
if (result !== null) {
|
|
755
|
-
result += "\n";
|
|
756
|
-
}
|
|
757
|
-
} else {}
|
|
758
|
-
if (!result) {
|
|
759
|
-
return null;
|
|
760
|
-
}
|
|
761
|
-
FS_stdin_getChar_buffer = intArrayFromString(result, true);
|
|
762
|
-
}
|
|
763
|
-
return FS_stdin_getChar_buffer.shift();
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
var TTY = {
|
|
767
|
-
ttys: [],
|
|
768
|
-
init() {},
|
|
769
|
-
shutdown() {},
|
|
770
|
-
register(dev, ops) {
|
|
771
|
-
TTY.ttys[dev] = {
|
|
772
|
-
input: [],
|
|
773
|
-
output: [],
|
|
774
|
-
ops
|
|
775
|
-
};
|
|
776
|
-
FS.registerDevice(dev, TTY.stream_ops);
|
|
777
|
-
},
|
|
778
|
-
stream_ops: {
|
|
779
|
-
open(stream) {
|
|
780
|
-
var tty = TTY.ttys[stream.node.rdev];
|
|
781
|
-
if (!tty) {
|
|
782
|
-
throw new FS.ErrnoError(43);
|
|
783
|
-
}
|
|
784
|
-
stream.tty = tty;
|
|
785
|
-
stream.seekable = false;
|
|
786
|
-
},
|
|
787
|
-
close(stream) {
|
|
788
|
-
// flush any pending line data
|
|
789
|
-
stream.tty.ops.fsync(stream.tty);
|
|
790
|
-
},
|
|
791
|
-
fsync(stream) {
|
|
792
|
-
stream.tty.ops.fsync(stream.tty);
|
|
793
|
-
},
|
|
794
|
-
read(stream, buffer, offset, length, pos) {
|
|
795
|
-
if (!stream.tty || !stream.tty.ops.get_char) {
|
|
796
|
-
throw new FS.ErrnoError(60);
|
|
797
|
-
}
|
|
798
|
-
var bytesRead = 0;
|
|
799
|
-
for (var i = 0; i < length; i++) {
|
|
800
|
-
var result;
|
|
801
|
-
try {
|
|
802
|
-
result = stream.tty.ops.get_char(stream.tty);
|
|
803
|
-
} catch (e) {
|
|
804
|
-
throw new FS.ErrnoError(29);
|
|
805
|
-
}
|
|
806
|
-
if (result === undefined && bytesRead === 0) {
|
|
807
|
-
throw new FS.ErrnoError(6);
|
|
808
|
-
}
|
|
809
|
-
if (result === null || result === undefined) break;
|
|
810
|
-
bytesRead++;
|
|
811
|
-
buffer[offset + i] = result;
|
|
812
|
-
}
|
|
813
|
-
if (bytesRead) {
|
|
814
|
-
stream.node.atime = Date.now();
|
|
815
|
-
}
|
|
816
|
-
return bytesRead;
|
|
817
|
-
},
|
|
818
|
-
write(stream, buffer, offset, length, pos) {
|
|
819
|
-
if (!stream.tty || !stream.tty.ops.put_char) {
|
|
820
|
-
throw new FS.ErrnoError(60);
|
|
821
|
-
}
|
|
822
|
-
try {
|
|
823
|
-
for (var i = 0; i < length; i++) {
|
|
824
|
-
stream.tty.ops.put_char(stream.tty, buffer[offset + i]);
|
|
825
|
-
}
|
|
826
|
-
} catch (e) {
|
|
827
|
-
throw new FS.ErrnoError(29);
|
|
828
|
-
}
|
|
829
|
-
if (length) {
|
|
830
|
-
stream.node.mtime = stream.node.ctime = Date.now();
|
|
831
|
-
}
|
|
832
|
-
return i;
|
|
833
|
-
}
|
|
834
|
-
},
|
|
835
|
-
default_tty_ops: {
|
|
836
|
-
get_char(tty) {
|
|
837
|
-
return FS_stdin_getChar();
|
|
838
|
-
},
|
|
839
|
-
put_char(tty, val) {
|
|
840
|
-
if (val === null || val === 10) {
|
|
841
|
-
out(UTF8ArrayToString(tty.output));
|
|
842
|
-
tty.output = [];
|
|
843
|
-
} else {
|
|
844
|
-
if (val != 0) tty.output.push(val);
|
|
845
|
-
}
|
|
846
|
-
},
|
|
847
|
-
fsync(tty) {
|
|
848
|
-
if (tty.output?.length > 0) {
|
|
849
|
-
out(UTF8ArrayToString(tty.output));
|
|
850
|
-
tty.output = [];
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
ioctl_tcgets(tty) {
|
|
854
|
-
// typical setting
|
|
855
|
-
return {
|
|
856
|
-
c_iflag: 25856,
|
|
857
|
-
c_oflag: 5,
|
|
858
|
-
c_cflag: 191,
|
|
859
|
-
c_lflag: 35387,
|
|
860
|
-
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 ]
|
|
861
|
-
};
|
|
862
|
-
},
|
|
863
|
-
ioctl_tcsets(tty, optional_actions, data) {
|
|
864
|
-
// currently just ignore
|
|
865
|
-
return 0;
|
|
866
|
-
},
|
|
867
|
-
ioctl_tiocgwinsz(tty) {
|
|
868
|
-
return [ 24, 80 ];
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
default_tty1_ops: {
|
|
872
|
-
put_char(tty, val) {
|
|
873
|
-
if (val === null || val === 10) {
|
|
874
|
-
err(UTF8ArrayToString(tty.output));
|
|
875
|
-
tty.output = [];
|
|
876
|
-
} else {
|
|
877
|
-
if (val != 0) tty.output.push(val);
|
|
878
|
-
}
|
|
879
|
-
},
|
|
880
|
-
fsync(tty) {
|
|
881
|
-
if (tty.output?.length > 0) {
|
|
882
|
-
err(UTF8ArrayToString(tty.output));
|
|
883
|
-
tty.output = [];
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
var mmapAlloc = size => {
|
|
890
|
-
abort();
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
var MEMFS = {
|
|
894
|
-
ops_table: null,
|
|
895
|
-
mount(mount) {
|
|
896
|
-
return MEMFS.createNode(null, "/", 16895, 0);
|
|
897
|
-
},
|
|
898
|
-
createNode(parent, name, mode, dev) {
|
|
899
|
-
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
|
|
900
|
-
// no supported
|
|
901
|
-
throw new FS.ErrnoError(63);
|
|
902
|
-
}
|
|
903
|
-
MEMFS.ops_table ||= {
|
|
904
|
-
dir: {
|
|
905
|
-
node: {
|
|
906
|
-
getattr: MEMFS.node_ops.getattr,
|
|
907
|
-
setattr: MEMFS.node_ops.setattr,
|
|
908
|
-
lookup: MEMFS.node_ops.lookup,
|
|
909
|
-
mknod: MEMFS.node_ops.mknod,
|
|
910
|
-
rename: MEMFS.node_ops.rename,
|
|
911
|
-
unlink: MEMFS.node_ops.unlink,
|
|
912
|
-
rmdir: MEMFS.node_ops.rmdir,
|
|
913
|
-
readdir: MEMFS.node_ops.readdir,
|
|
914
|
-
symlink: MEMFS.node_ops.symlink
|
|
915
|
-
},
|
|
916
|
-
stream: {
|
|
917
|
-
llseek: MEMFS.stream_ops.llseek
|
|
918
|
-
}
|
|
919
|
-
},
|
|
920
|
-
file: {
|
|
921
|
-
node: {
|
|
922
|
-
getattr: MEMFS.node_ops.getattr,
|
|
923
|
-
setattr: MEMFS.node_ops.setattr
|
|
924
|
-
},
|
|
925
|
-
stream: {
|
|
926
|
-
llseek: MEMFS.stream_ops.llseek,
|
|
927
|
-
read: MEMFS.stream_ops.read,
|
|
928
|
-
write: MEMFS.stream_ops.write,
|
|
929
|
-
mmap: MEMFS.stream_ops.mmap,
|
|
930
|
-
msync: MEMFS.stream_ops.msync
|
|
931
|
-
}
|
|
932
|
-
},
|
|
933
|
-
link: {
|
|
934
|
-
node: {
|
|
935
|
-
getattr: MEMFS.node_ops.getattr,
|
|
936
|
-
setattr: MEMFS.node_ops.setattr,
|
|
937
|
-
readlink: MEMFS.node_ops.readlink
|
|
938
|
-
},
|
|
939
|
-
stream: {}
|
|
940
|
-
},
|
|
941
|
-
chrdev: {
|
|
942
|
-
node: {
|
|
943
|
-
getattr: MEMFS.node_ops.getattr,
|
|
944
|
-
setattr: MEMFS.node_ops.setattr
|
|
945
|
-
},
|
|
946
|
-
stream: FS.chrdev_stream_ops
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
var node = FS.createNode(parent, name, mode, dev);
|
|
950
|
-
if (FS.isDir(node.mode)) {
|
|
951
|
-
node.node_ops = MEMFS.ops_table.dir.node;
|
|
952
|
-
node.stream_ops = MEMFS.ops_table.dir.stream;
|
|
953
|
-
node.contents = {};
|
|
954
|
-
} else if (FS.isFile(node.mode)) {
|
|
955
|
-
node.node_ops = MEMFS.ops_table.file.node;
|
|
956
|
-
node.stream_ops = MEMFS.ops_table.file.stream;
|
|
957
|
-
node.usedBytes = 0;
|
|
958
|
-
// The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
|
|
959
|
-
// When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred
|
|
960
|
-
// for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
|
|
961
|
-
// penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
|
|
962
|
-
node.contents = null;
|
|
963
|
-
} else if (FS.isLink(node.mode)) {
|
|
964
|
-
node.node_ops = MEMFS.ops_table.link.node;
|
|
965
|
-
node.stream_ops = MEMFS.ops_table.link.stream;
|
|
966
|
-
} else if (FS.isChrdev(node.mode)) {
|
|
967
|
-
node.node_ops = MEMFS.ops_table.chrdev.node;
|
|
968
|
-
node.stream_ops = MEMFS.ops_table.chrdev.stream;
|
|
969
|
-
}
|
|
970
|
-
node.atime = node.mtime = node.ctime = Date.now();
|
|
971
|
-
// add the new node to the parent
|
|
972
|
-
if (parent) {
|
|
973
|
-
parent.contents[name] = node;
|
|
974
|
-
parent.atime = parent.mtime = parent.ctime = node.atime;
|
|
975
|
-
}
|
|
976
|
-
return node;
|
|
977
|
-
},
|
|
978
|
-
getFileDataAsTypedArray(node) {
|
|
979
|
-
if (!node.contents) return new Uint8Array(0);
|
|
980
|
-
if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes);
|
|
981
|
-
// Make sure to not return excess unused bytes.
|
|
982
|
-
return new Uint8Array(node.contents);
|
|
983
|
-
},
|
|
984
|
-
expandFileStorage(node, newCapacity) {
|
|
985
|
-
var prevCapacity = node.contents ? node.contents.length : 0;
|
|
986
|
-
if (prevCapacity >= newCapacity) return;
|
|
987
|
-
// No need to expand, the storage was already large enough.
|
|
988
|
-
// Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
|
|
989
|
-
// For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
|
|
990
|
-
// avoid overshooting the allocation cap by a very large margin.
|
|
991
|
-
var CAPACITY_DOUBLING_MAX = 1024 * 1024;
|
|
992
|
-
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125)) >>> 0);
|
|
993
|
-
if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256);
|
|
994
|
-
// At minimum allocate 256b for each file when expanding.
|
|
995
|
-
var oldContents = node.contents;
|
|
996
|
-
node.contents = new Uint8Array(newCapacity);
|
|
997
|
-
// Allocate new storage.
|
|
998
|
-
if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0);
|
|
999
|
-
},
|
|
1000
|
-
resizeFileStorage(node, newSize) {
|
|
1001
|
-
if (node.usedBytes == newSize) return;
|
|
1002
|
-
if (newSize == 0) {
|
|
1003
|
-
node.contents = null;
|
|
1004
|
-
// Fully decommit when requesting a resize to zero.
|
|
1005
|
-
node.usedBytes = 0;
|
|
1006
|
-
} else {
|
|
1007
|
-
var oldContents = node.contents;
|
|
1008
|
-
node.contents = new Uint8Array(newSize);
|
|
1009
|
-
// Allocate new storage.
|
|
1010
|
-
if (oldContents) {
|
|
1011
|
-
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
|
|
1012
|
-
}
|
|
1013
|
-
node.usedBytes = newSize;
|
|
1014
|
-
}
|
|
1015
|
-
},
|
|
1016
|
-
node_ops: {
|
|
1017
|
-
getattr(node) {
|
|
1018
|
-
var attr = {};
|
|
1019
|
-
// device numbers reuse inode numbers.
|
|
1020
|
-
attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
|
|
1021
|
-
attr.ino = node.id;
|
|
1022
|
-
attr.mode = node.mode;
|
|
1023
|
-
attr.nlink = 1;
|
|
1024
|
-
attr.uid = 0;
|
|
1025
|
-
attr.gid = 0;
|
|
1026
|
-
attr.rdev = node.rdev;
|
|
1027
|
-
if (FS.isDir(node.mode)) {
|
|
1028
|
-
attr.size = 4096;
|
|
1029
|
-
} else if (FS.isFile(node.mode)) {
|
|
1030
|
-
attr.size = node.usedBytes;
|
|
1031
|
-
} else if (FS.isLink(node.mode)) {
|
|
1032
|
-
attr.size = node.link.length;
|
|
1033
|
-
} else {
|
|
1034
|
-
attr.size = 0;
|
|
1035
|
-
}
|
|
1036
|
-
attr.atime = new Date(node.atime);
|
|
1037
|
-
attr.mtime = new Date(node.mtime);
|
|
1038
|
-
attr.ctime = new Date(node.ctime);
|
|
1039
|
-
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
|
|
1040
|
-
// but this is not required by the standard.
|
|
1041
|
-
attr.blksize = 4096;
|
|
1042
|
-
attr.blocks = Math.ceil(attr.size / attr.blksize);
|
|
1043
|
-
return attr;
|
|
1044
|
-
},
|
|
1045
|
-
setattr(node, attr) {
|
|
1046
|
-
for (const key of [ "mode", "atime", "mtime", "ctime" ]) {
|
|
1047
|
-
if (attr[key] != null) {
|
|
1048
|
-
node[key] = attr[key];
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
if (attr.size !== undefined) {
|
|
1052
|
-
MEMFS.resizeFileStorage(node, attr.size);
|
|
1053
|
-
}
|
|
1054
|
-
},
|
|
1055
|
-
lookup(parent, name) {
|
|
1056
|
-
throw MEMFS.doesNotExistError;
|
|
1057
|
-
},
|
|
1058
|
-
mknod(parent, name, mode, dev) {
|
|
1059
|
-
return MEMFS.createNode(parent, name, mode, dev);
|
|
1060
|
-
},
|
|
1061
|
-
rename(old_node, new_dir, new_name) {
|
|
1062
|
-
var new_node;
|
|
1063
|
-
try {
|
|
1064
|
-
new_node = FS.lookupNode(new_dir, new_name);
|
|
1065
|
-
} catch (e) {}
|
|
1066
|
-
if (new_node) {
|
|
1067
|
-
if (FS.isDir(old_node.mode)) {
|
|
1068
|
-
// if we're overwriting a directory at new_name, make sure it's empty.
|
|
1069
|
-
for (var i in new_node.contents) {
|
|
1070
|
-
throw new FS.ErrnoError(55);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
FS.hashRemoveNode(new_node);
|
|
1074
|
-
}
|
|
1075
|
-
// do the internal rewiring
|
|
1076
|
-
delete old_node.parent.contents[old_node.name];
|
|
1077
|
-
new_dir.contents[new_name] = old_node;
|
|
1078
|
-
old_node.name = new_name;
|
|
1079
|
-
new_dir.ctime = new_dir.mtime = old_node.parent.ctime = old_node.parent.mtime = Date.now();
|
|
1080
|
-
},
|
|
1081
|
-
unlink(parent, name) {
|
|
1082
|
-
delete parent.contents[name];
|
|
1083
|
-
parent.ctime = parent.mtime = Date.now();
|
|
1084
|
-
},
|
|
1085
|
-
rmdir(parent, name) {
|
|
1086
|
-
var node = FS.lookupNode(parent, name);
|
|
1087
|
-
for (var i in node.contents) {
|
|
1088
|
-
throw new FS.ErrnoError(55);
|
|
1089
|
-
}
|
|
1090
|
-
delete parent.contents[name];
|
|
1091
|
-
parent.ctime = parent.mtime = Date.now();
|
|
1092
|
-
},
|
|
1093
|
-
readdir(node) {
|
|
1094
|
-
return [ ".", "..", ...Object.keys(node.contents) ];
|
|
1095
|
-
},
|
|
1096
|
-
symlink(parent, newname, oldpath) {
|
|
1097
|
-
var node = MEMFS.createNode(parent, newname, 511 | 40960, 0);
|
|
1098
|
-
node.link = oldpath;
|
|
1099
|
-
return node;
|
|
1100
|
-
},
|
|
1101
|
-
readlink(node) {
|
|
1102
|
-
if (!FS.isLink(node.mode)) {
|
|
1103
|
-
throw new FS.ErrnoError(28);
|
|
1104
|
-
}
|
|
1105
|
-
return node.link;
|
|
1106
|
-
}
|
|
1107
|
-
},
|
|
1108
|
-
stream_ops: {
|
|
1109
|
-
read(stream, buffer, offset, length, position) {
|
|
1110
|
-
var contents = stream.node.contents;
|
|
1111
|
-
if (position >= stream.node.usedBytes) return 0;
|
|
1112
|
-
var size = Math.min(stream.node.usedBytes - position, length);
|
|
1113
|
-
if (size > 8 && contents.subarray) {
|
|
1114
|
-
// non-trivial, and typed array
|
|
1115
|
-
buffer.set(contents.subarray(position, position + size), offset);
|
|
1116
|
-
} else {
|
|
1117
|
-
for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
|
|
1118
|
-
}
|
|
1119
|
-
return size;
|
|
1120
|
-
},
|
|
1121
|
-
write(stream, buffer, offset, length, position, canOwn) {
|
|
1122
|
-
// If the buffer is located in main memory (HEAP), and if
|
|
1123
|
-
// memory can grow, we can't hold on to references of the
|
|
1124
|
-
// memory buffer, as they may get invalidated. That means we
|
|
1125
|
-
// need to do copy its contents.
|
|
1126
|
-
if (buffer.buffer === HEAP8.buffer) {
|
|
1127
|
-
canOwn = false;
|
|
1128
|
-
}
|
|
1129
|
-
if (!length) return 0;
|
|
1130
|
-
var node = stream.node;
|
|
1131
|
-
node.mtime = node.ctime = Date.now();
|
|
1132
|
-
if (buffer.subarray && (!node.contents || node.contents.subarray)) {
|
|
1133
|
-
// This write is from a typed array to a typed array?
|
|
1134
|
-
if (canOwn) {
|
|
1135
|
-
node.contents = buffer.subarray(offset, offset + length);
|
|
1136
|
-
node.usedBytes = length;
|
|
1137
|
-
return length;
|
|
1138
|
-
} else if (node.usedBytes === 0 && position === 0) {
|
|
1139
|
-
// If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
|
|
1140
|
-
node.contents = buffer.slice(offset, offset + length);
|
|
1141
|
-
node.usedBytes = length;
|
|
1142
|
-
return length;
|
|
1143
|
-
} else if (position + length <= node.usedBytes) {
|
|
1144
|
-
// Writing to an already allocated and used subrange of the file?
|
|
1145
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1146
|
-
return length;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
// Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
|
|
1150
|
-
MEMFS.expandFileStorage(node, position + length);
|
|
1151
|
-
if (node.contents.subarray && buffer.subarray) {
|
|
1152
|
-
// Use typed array write which is available.
|
|
1153
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1154
|
-
} else {
|
|
1155
|
-
for (var i = 0; i < length; i++) {
|
|
1156
|
-
node.contents[position + i] = buffer[offset + i];
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
1160
|
-
return length;
|
|
1161
|
-
},
|
|
1162
|
-
llseek(stream, offset, whence) {
|
|
1163
|
-
var position = offset;
|
|
1164
|
-
if (whence === 1) {
|
|
1165
|
-
position += stream.position;
|
|
1166
|
-
} else if (whence === 2) {
|
|
1167
|
-
if (FS.isFile(stream.node.mode)) {
|
|
1168
|
-
position += stream.node.usedBytes;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
if (position < 0) {
|
|
1172
|
-
throw new FS.ErrnoError(28);
|
|
1173
|
-
}
|
|
1174
|
-
return position;
|
|
1175
|
-
},
|
|
1176
|
-
mmap(stream, length, position, prot, flags) {
|
|
1177
|
-
if (!FS.isFile(stream.node.mode)) {
|
|
1178
|
-
throw new FS.ErrnoError(43);
|
|
1179
|
-
}
|
|
1180
|
-
var ptr;
|
|
1181
|
-
var allocated;
|
|
1182
|
-
var contents = stream.node.contents;
|
|
1183
|
-
// Only make a new copy when MAP_PRIVATE is specified.
|
|
1184
|
-
if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
|
|
1185
|
-
// We can't emulate MAP_SHARED when the file is not backed by the
|
|
1186
|
-
// buffer we're mapping to (e.g. the HEAP buffer).
|
|
1187
|
-
allocated = false;
|
|
1188
|
-
ptr = contents.byteOffset;
|
|
1189
|
-
} else {
|
|
1190
|
-
allocated = true;
|
|
1191
|
-
ptr = mmapAlloc(length);
|
|
1192
|
-
if (!ptr) {
|
|
1193
|
-
throw new FS.ErrnoError(48);
|
|
1194
|
-
}
|
|
1195
|
-
if (contents) {
|
|
1196
|
-
// Try to avoid unnecessary slices.
|
|
1197
|
-
if (position > 0 || position + length < contents.length) {
|
|
1198
|
-
if (contents.subarray) {
|
|
1199
|
-
contents = contents.subarray(position, position + length);
|
|
1200
|
-
} else {
|
|
1201
|
-
contents = Array.prototype.slice.call(contents, position, position + length);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
HEAP8.set(contents, ptr);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
return {
|
|
1208
|
-
ptr,
|
|
1209
|
-
allocated
|
|
1210
|
-
};
|
|
1211
|
-
},
|
|
1212
|
-
msync(stream, buffer, offset, length, mmapFlags) {
|
|
1213
|
-
MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
|
|
1214
|
-
// should we check if bytesWritten and length are the same?
|
|
1215
|
-
return 0;
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
var asyncLoad = async url => {
|
|
1221
|
-
var arrayBuffer = await readAsync(url);
|
|
1222
|
-
return new Uint8Array(arrayBuffer);
|
|
1223
|
-
};
|
|
1224
|
-
|
|
1225
|
-
var FS_createDataFile = (...args) => FS.createDataFile(...args);
|
|
1226
|
-
|
|
1227
|
-
var preloadPlugins = [];
|
|
1228
|
-
|
|
1229
|
-
var FS_handledByPreloadPlugin = (byteArray, fullname, finish, onerror) => {
|
|
1230
|
-
// Ensure plugins are ready.
|
|
1231
|
-
if (typeof Browser != "undefined") Browser.init();
|
|
1232
|
-
var handled = false;
|
|
1233
|
-
preloadPlugins.forEach(plugin => {
|
|
1234
|
-
if (handled) return;
|
|
1235
|
-
if (plugin["canHandle"](fullname)) {
|
|
1236
|
-
plugin["handle"](byteArray, fullname, finish, onerror);
|
|
1237
|
-
handled = true;
|
|
1238
|
-
}
|
|
1239
|
-
});
|
|
1240
|
-
return handled;
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
|
|
1244
|
-
// TODO we should allow people to just pass in a complete filename instead
|
|
1245
|
-
// of parent and name being that we just join them anyways
|
|
1246
|
-
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
|
|
1247
|
-
var dep = getUniqueRunDependency(`cp ${fullname}`);
|
|
1248
|
-
// might have several active requests for the same fullname
|
|
1249
|
-
function processData(byteArray) {
|
|
1250
|
-
function finish(byteArray) {
|
|
1251
|
-
preFinish?.();
|
|
1252
|
-
if (!dontCreateFile) {
|
|
1253
|
-
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
|
1254
|
-
}
|
|
1255
|
-
onload?.();
|
|
1256
|
-
removeRunDependency(dep);
|
|
1257
|
-
}
|
|
1258
|
-
if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
|
|
1259
|
-
onerror?.();
|
|
1260
|
-
removeRunDependency(dep);
|
|
1261
|
-
})) {
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
finish(byteArray);
|
|
1265
|
-
}
|
|
1266
|
-
addRunDependency(dep);
|
|
1267
|
-
if (typeof url == "string") {
|
|
1268
|
-
asyncLoad(url).then(processData, onerror);
|
|
1269
|
-
} else {
|
|
1270
|
-
processData(url);
|
|
1271
|
-
}
|
|
1272
|
-
};
|
|
1273
|
-
|
|
1274
|
-
var FS_modeStringToFlags = str => {
|
|
1275
|
-
var flagModes = {
|
|
1276
|
-
"r": 0,
|
|
1277
|
-
"r+": 2,
|
|
1278
|
-
"w": 512 | 64 | 1,
|
|
1279
|
-
"w+": 512 | 64 | 2,
|
|
1280
|
-
"a": 1024 | 64 | 1,
|
|
1281
|
-
"a+": 1024 | 64 | 2
|
|
1282
|
-
};
|
|
1283
|
-
var flags = flagModes[str];
|
|
1284
|
-
if (typeof flags == "undefined") {
|
|
1285
|
-
throw new Error(`Unknown file open mode: ${str}`);
|
|
1286
|
-
}
|
|
1287
|
-
return flags;
|
|
1288
|
-
};
|
|
1289
|
-
|
|
1290
|
-
var FS_getMode = (canRead, canWrite) => {
|
|
1291
|
-
var mode = 0;
|
|
1292
|
-
if (canRead) mode |= 292 | 73;
|
|
1293
|
-
if (canWrite) mode |= 146;
|
|
1294
|
-
return mode;
|
|
1295
|
-
};
|
|
1296
|
-
|
|
1297
|
-
var ERRNO_CODES = {
|
|
1298
|
-
"EPERM": 63,
|
|
1299
|
-
"ENOENT": 44,
|
|
1300
|
-
"ESRCH": 71,
|
|
1301
|
-
"EINTR": 27,
|
|
1302
|
-
"EIO": 29,
|
|
1303
|
-
"ENXIO": 60,
|
|
1304
|
-
"E2BIG": 1,
|
|
1305
|
-
"ENOEXEC": 45,
|
|
1306
|
-
"EBADF": 8,
|
|
1307
|
-
"ECHILD": 12,
|
|
1308
|
-
"EAGAIN": 6,
|
|
1309
|
-
"EWOULDBLOCK": 6,
|
|
1310
|
-
"ENOMEM": 48,
|
|
1311
|
-
"EACCES": 2,
|
|
1312
|
-
"EFAULT": 21,
|
|
1313
|
-
"ENOTBLK": 105,
|
|
1314
|
-
"EBUSY": 10,
|
|
1315
|
-
"EEXIST": 20,
|
|
1316
|
-
"EXDEV": 75,
|
|
1317
|
-
"ENODEV": 43,
|
|
1318
|
-
"ENOTDIR": 54,
|
|
1319
|
-
"EISDIR": 31,
|
|
1320
|
-
"EINVAL": 28,
|
|
1321
|
-
"ENFILE": 41,
|
|
1322
|
-
"EMFILE": 33,
|
|
1323
|
-
"ENOTTY": 59,
|
|
1324
|
-
"ETXTBSY": 74,
|
|
1325
|
-
"EFBIG": 22,
|
|
1326
|
-
"ENOSPC": 51,
|
|
1327
|
-
"ESPIPE": 70,
|
|
1328
|
-
"EROFS": 69,
|
|
1329
|
-
"EMLINK": 34,
|
|
1330
|
-
"EPIPE": 64,
|
|
1331
|
-
"EDOM": 18,
|
|
1332
|
-
"ERANGE": 68,
|
|
1333
|
-
"ENOMSG": 49,
|
|
1334
|
-
"EIDRM": 24,
|
|
1335
|
-
"ECHRNG": 106,
|
|
1336
|
-
"EL2NSYNC": 156,
|
|
1337
|
-
"EL3HLT": 107,
|
|
1338
|
-
"EL3RST": 108,
|
|
1339
|
-
"ELNRNG": 109,
|
|
1340
|
-
"EUNATCH": 110,
|
|
1341
|
-
"ENOCSI": 111,
|
|
1342
|
-
"EL2HLT": 112,
|
|
1343
|
-
"EDEADLK": 16,
|
|
1344
|
-
"ENOLCK": 46,
|
|
1345
|
-
"EBADE": 113,
|
|
1346
|
-
"EBADR": 114,
|
|
1347
|
-
"EXFULL": 115,
|
|
1348
|
-
"ENOANO": 104,
|
|
1349
|
-
"EBADRQC": 103,
|
|
1350
|
-
"EBADSLT": 102,
|
|
1351
|
-
"EDEADLOCK": 16,
|
|
1352
|
-
"EBFONT": 101,
|
|
1353
|
-
"ENOSTR": 100,
|
|
1354
|
-
"ENODATA": 116,
|
|
1355
|
-
"ETIME": 117,
|
|
1356
|
-
"ENOSR": 118,
|
|
1357
|
-
"ENONET": 119,
|
|
1358
|
-
"ENOPKG": 120,
|
|
1359
|
-
"EREMOTE": 121,
|
|
1360
|
-
"ENOLINK": 47,
|
|
1361
|
-
"EADV": 122,
|
|
1362
|
-
"ESRMNT": 123,
|
|
1363
|
-
"ECOMM": 124,
|
|
1364
|
-
"EPROTO": 65,
|
|
1365
|
-
"EMULTIHOP": 36,
|
|
1366
|
-
"EDOTDOT": 125,
|
|
1367
|
-
"EBADMSG": 9,
|
|
1368
|
-
"ENOTUNIQ": 126,
|
|
1369
|
-
"EBADFD": 127,
|
|
1370
|
-
"EREMCHG": 128,
|
|
1371
|
-
"ELIBACC": 129,
|
|
1372
|
-
"ELIBBAD": 130,
|
|
1373
|
-
"ELIBSCN": 131,
|
|
1374
|
-
"ELIBMAX": 132,
|
|
1375
|
-
"ELIBEXEC": 133,
|
|
1376
|
-
"ENOSYS": 52,
|
|
1377
|
-
"ENOTEMPTY": 55,
|
|
1378
|
-
"ENAMETOOLONG": 37,
|
|
1379
|
-
"ELOOP": 32,
|
|
1380
|
-
"EOPNOTSUPP": 138,
|
|
1381
|
-
"EPFNOSUPPORT": 139,
|
|
1382
|
-
"ECONNRESET": 15,
|
|
1383
|
-
"ENOBUFS": 42,
|
|
1384
|
-
"EAFNOSUPPORT": 5,
|
|
1385
|
-
"EPROTOTYPE": 67,
|
|
1386
|
-
"ENOTSOCK": 57,
|
|
1387
|
-
"ENOPROTOOPT": 50,
|
|
1388
|
-
"ESHUTDOWN": 140,
|
|
1389
|
-
"ECONNREFUSED": 14,
|
|
1390
|
-
"EADDRINUSE": 3,
|
|
1391
|
-
"ECONNABORTED": 13,
|
|
1392
|
-
"ENETUNREACH": 40,
|
|
1393
|
-
"ENETDOWN": 38,
|
|
1394
|
-
"ETIMEDOUT": 73,
|
|
1395
|
-
"EHOSTDOWN": 142,
|
|
1396
|
-
"EHOSTUNREACH": 23,
|
|
1397
|
-
"EINPROGRESS": 26,
|
|
1398
|
-
"EALREADY": 7,
|
|
1399
|
-
"EDESTADDRREQ": 17,
|
|
1400
|
-
"EMSGSIZE": 35,
|
|
1401
|
-
"EPROTONOSUPPORT": 66,
|
|
1402
|
-
"ESOCKTNOSUPPORT": 137,
|
|
1403
|
-
"EADDRNOTAVAIL": 4,
|
|
1404
|
-
"ENETRESET": 39,
|
|
1405
|
-
"EISCONN": 30,
|
|
1406
|
-
"ENOTCONN": 53,
|
|
1407
|
-
"ETOOMANYREFS": 141,
|
|
1408
|
-
"EUSERS": 136,
|
|
1409
|
-
"EDQUOT": 19,
|
|
1410
|
-
"ESTALE": 72,
|
|
1411
|
-
"ENOTSUP": 138,
|
|
1412
|
-
"ENOMEDIUM": 148,
|
|
1413
|
-
"EILSEQ": 25,
|
|
1414
|
-
"EOVERFLOW": 61,
|
|
1415
|
-
"ECANCELED": 11,
|
|
1416
|
-
"ENOTRECOVERABLE": 56,
|
|
1417
|
-
"EOWNERDEAD": 62,
|
|
1418
|
-
"ESTRPIPE": 135
|
|
1419
|
-
};
|
|
1420
|
-
|
|
1421
|
-
var PROXYFS = {
|
|
1422
|
-
mount(mount) {
|
|
1423
|
-
return PROXYFS.createNode(null, "/", mount.opts.fs.lstat(mount.opts.root).mode, 0);
|
|
1424
|
-
},
|
|
1425
|
-
createNode(parent, name, mode, dev) {
|
|
1426
|
-
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
|
|
1427
|
-
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
1428
|
-
}
|
|
1429
|
-
var node = FS.createNode(parent, name, mode);
|
|
1430
|
-
node.node_ops = PROXYFS.node_ops;
|
|
1431
|
-
node.stream_ops = PROXYFS.stream_ops;
|
|
1432
|
-
return node;
|
|
1433
|
-
},
|
|
1434
|
-
realPath(node) {
|
|
1435
|
-
var parts = [];
|
|
1436
|
-
while (node.parent !== node) {
|
|
1437
|
-
parts.push(node.name);
|
|
1438
|
-
node = node.parent;
|
|
1439
|
-
}
|
|
1440
|
-
parts.push(node.mount.opts.root);
|
|
1441
|
-
parts.reverse();
|
|
1442
|
-
return PATH.join(...parts);
|
|
1443
|
-
},
|
|
1444
|
-
node_ops: {
|
|
1445
|
-
getattr(node) {
|
|
1446
|
-
var path = PROXYFS.realPath(node);
|
|
1447
|
-
var stat;
|
|
1448
|
-
try {
|
|
1449
|
-
stat = node.mount.opts.fs.lstat(path);
|
|
1450
|
-
} catch (e) {
|
|
1451
|
-
if (!e.code) throw e;
|
|
1452
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1453
|
-
}
|
|
1454
|
-
return {
|
|
1455
|
-
dev: stat.dev,
|
|
1456
|
-
ino: stat.ino,
|
|
1457
|
-
mode: stat.mode,
|
|
1458
|
-
nlink: stat.nlink,
|
|
1459
|
-
uid: stat.uid,
|
|
1460
|
-
gid: stat.gid,
|
|
1461
|
-
rdev: stat.rdev,
|
|
1462
|
-
size: stat.size,
|
|
1463
|
-
atime: stat.atime,
|
|
1464
|
-
mtime: stat.mtime,
|
|
1465
|
-
ctime: stat.ctime,
|
|
1466
|
-
blksize: stat.blksize,
|
|
1467
|
-
blocks: stat.blocks
|
|
1468
|
-
};
|
|
1469
|
-
},
|
|
1470
|
-
setattr(node, attr) {
|
|
1471
|
-
var path = PROXYFS.realPath(node);
|
|
1472
|
-
try {
|
|
1473
|
-
if (attr.mode !== undefined) {
|
|
1474
|
-
node.mount.opts.fs.chmod(path, attr.mode);
|
|
1475
|
-
// update the common node structure mode as well
|
|
1476
|
-
node.mode = attr.mode;
|
|
1477
|
-
}
|
|
1478
|
-
if (attr.atime || attr.mtime) {
|
|
1479
|
-
var atime = new Date(attr.atime || attr.mtime);
|
|
1480
|
-
var mtime = new Date(attr.mtime || attr.atime);
|
|
1481
|
-
node.mount.opts.fs.utime(path, atime, mtime);
|
|
1482
|
-
}
|
|
1483
|
-
if (attr.size !== undefined) {
|
|
1484
|
-
node.mount.opts.fs.truncate(path, attr.size);
|
|
1485
|
-
}
|
|
1486
|
-
} catch (e) {
|
|
1487
|
-
if (!e.code) throw e;
|
|
1488
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1489
|
-
}
|
|
1490
|
-
},
|
|
1491
|
-
lookup(parent, name) {
|
|
1492
|
-
try {
|
|
1493
|
-
var path = PATH.join2(PROXYFS.realPath(parent), name);
|
|
1494
|
-
var mode = parent.mount.opts.fs.lstat(path).mode;
|
|
1495
|
-
var node = PROXYFS.createNode(parent, name, mode);
|
|
1496
|
-
return node;
|
|
1497
|
-
} catch (e) {
|
|
1498
|
-
if (!e.code) throw e;
|
|
1499
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1500
|
-
}
|
|
1501
|
-
},
|
|
1502
|
-
mknod(parent, name, mode, dev) {
|
|
1503
|
-
var node = PROXYFS.createNode(parent, name, mode, dev);
|
|
1504
|
-
// create the backing node for this in the fs root as well
|
|
1505
|
-
var path = PROXYFS.realPath(node);
|
|
1506
|
-
try {
|
|
1507
|
-
if (FS.isDir(node.mode)) {
|
|
1508
|
-
node.mount.opts.fs.mkdir(path, node.mode);
|
|
1509
|
-
} else {
|
|
1510
|
-
node.mount.opts.fs.writeFile(path, "", {
|
|
1511
|
-
mode: node.mode
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
} catch (e) {
|
|
1515
|
-
if (!e.code) throw e;
|
|
1516
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1517
|
-
}
|
|
1518
|
-
return node;
|
|
1519
|
-
},
|
|
1520
|
-
rename(oldNode, newDir, newName) {
|
|
1521
|
-
var oldPath = PROXYFS.realPath(oldNode);
|
|
1522
|
-
var newPath = PATH.join2(PROXYFS.realPath(newDir), newName);
|
|
1523
|
-
try {
|
|
1524
|
-
FS.unlink(newPath);
|
|
1525
|
-
} catch (e) {}
|
|
1526
|
-
try {
|
|
1527
|
-
oldNode.mount.opts.fs.rename(oldPath, newPath);
|
|
1528
|
-
oldNode.name = newName;
|
|
1529
|
-
} catch (e) {
|
|
1530
|
-
if (!e.code) throw e;
|
|
1531
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1532
|
-
}
|
|
1533
|
-
},
|
|
1534
|
-
unlink(parent, name) {
|
|
1535
|
-
var path = PATH.join2(PROXYFS.realPath(parent), name);
|
|
1536
|
-
try {
|
|
1537
|
-
parent.mount.opts.fs.unlink(path);
|
|
1538
|
-
} catch (e) {
|
|
1539
|
-
if (!e.code) throw e;
|
|
1540
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1541
|
-
}
|
|
1542
|
-
},
|
|
1543
|
-
rmdir(parent, name) {
|
|
1544
|
-
var path = PATH.join2(PROXYFS.realPath(parent), name);
|
|
1545
|
-
try {
|
|
1546
|
-
parent.mount.opts.fs.rmdir(path);
|
|
1547
|
-
} catch (e) {
|
|
1548
|
-
if (!e.code) throw e;
|
|
1549
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1550
|
-
}
|
|
1551
|
-
},
|
|
1552
|
-
readdir(node) {
|
|
1553
|
-
var path = PROXYFS.realPath(node);
|
|
1554
|
-
try {
|
|
1555
|
-
return node.mount.opts.fs.readdir(path);
|
|
1556
|
-
} catch (e) {
|
|
1557
|
-
if (!e.code) throw e;
|
|
1558
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1559
|
-
}
|
|
1560
|
-
},
|
|
1561
|
-
symlink(parent, newName, oldPath) {
|
|
1562
|
-
var newPath = PATH.join2(PROXYFS.realPath(parent), newName);
|
|
1563
|
-
try {
|
|
1564
|
-
parent.mount.opts.fs.symlink(oldPath, newPath);
|
|
1565
|
-
} catch (e) {
|
|
1566
|
-
if (!e.code) throw e;
|
|
1567
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1568
|
-
}
|
|
1569
|
-
},
|
|
1570
|
-
readlink(node) {
|
|
1571
|
-
var path = PROXYFS.realPath(node);
|
|
1572
|
-
try {
|
|
1573
|
-
return node.mount.opts.fs.readlink(path);
|
|
1574
|
-
} catch (e) {
|
|
1575
|
-
if (!e.code) throw e;
|
|
1576
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
},
|
|
1580
|
-
stream_ops: {
|
|
1581
|
-
open(stream) {
|
|
1582
|
-
var path = PROXYFS.realPath(stream.node);
|
|
1583
|
-
try {
|
|
1584
|
-
stream.nfd = stream.node.mount.opts.fs.open(path, stream.flags);
|
|
1585
|
-
} catch (e) {
|
|
1586
|
-
if (!e.code) throw e;
|
|
1587
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1588
|
-
}
|
|
1589
|
-
},
|
|
1590
|
-
close(stream) {
|
|
1591
|
-
try {
|
|
1592
|
-
stream.node.mount.opts.fs.close(stream.nfd);
|
|
1593
|
-
} catch (e) {
|
|
1594
|
-
if (!e.code) throw e;
|
|
1595
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1596
|
-
}
|
|
1597
|
-
},
|
|
1598
|
-
read(stream, buffer, offset, length, position) {
|
|
1599
|
-
try {
|
|
1600
|
-
return stream.node.mount.opts.fs.read(stream.nfd, buffer, offset, length, position);
|
|
1601
|
-
} catch (e) {
|
|
1602
|
-
if (!e.code) throw e;
|
|
1603
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1604
|
-
}
|
|
1605
|
-
},
|
|
1606
|
-
write(stream, buffer, offset, length, position) {
|
|
1607
|
-
try {
|
|
1608
|
-
return stream.node.mount.opts.fs.write(stream.nfd, buffer, offset, length, position);
|
|
1609
|
-
} catch (e) {
|
|
1610
|
-
if (!e.code) throw e;
|
|
1611
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1612
|
-
}
|
|
1613
|
-
},
|
|
1614
|
-
llseek(stream, offset, whence) {
|
|
1615
|
-
var position = offset;
|
|
1616
|
-
if (whence === 1) {
|
|
1617
|
-
position += stream.position;
|
|
1618
|
-
} else if (whence === 2) {
|
|
1619
|
-
if (FS.isFile(stream.node.mode)) {
|
|
1620
|
-
try {
|
|
1621
|
-
var stat = stream.node.node_ops.getattr(stream.node);
|
|
1622
|
-
position += stat.size;
|
|
1623
|
-
} catch (e) {
|
|
1624
|
-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
if (position < 0) {
|
|
1629
|
-
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
|
1630
|
-
}
|
|
1631
|
-
return position;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
var FS = {
|
|
1637
|
-
root: null,
|
|
1638
|
-
mounts: [],
|
|
1639
|
-
devices: {},
|
|
1640
|
-
streams: [],
|
|
1641
|
-
nextInode: 1,
|
|
1642
|
-
nameTable: null,
|
|
1643
|
-
currentPath: "/",
|
|
1644
|
-
initialized: false,
|
|
1645
|
-
ignorePermissions: true,
|
|
1646
|
-
filesystems: null,
|
|
1647
|
-
syncFSRequests: 0,
|
|
1648
|
-
readFiles: {},
|
|
1649
|
-
ErrnoError: class {
|
|
1650
|
-
name="ErrnoError";
|
|
1651
|
-
// We set the `name` property to be able to identify `FS.ErrnoError`
|
|
1652
|
-
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
|
|
1653
|
-
// - when using PROXYFS, an error can come from an underlying FS
|
|
1654
|
-
// as different FS objects have their own FS.ErrnoError each,
|
|
1655
|
-
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
|
|
1656
|
-
// we'll use the reliable test `err.name == "ErrnoError"` instead
|
|
1657
|
-
constructor(errno) {
|
|
1658
|
-
this.errno = errno;
|
|
1659
|
-
}
|
|
1660
|
-
},
|
|
1661
|
-
FSStream: class {
|
|
1662
|
-
shared={};
|
|
1663
|
-
get object() {
|
|
1664
|
-
return this.node;
|
|
1665
|
-
}
|
|
1666
|
-
set object(val) {
|
|
1667
|
-
this.node = val;
|
|
1668
|
-
}
|
|
1669
|
-
get isRead() {
|
|
1670
|
-
return (this.flags & 2097155) !== 1;
|
|
1671
|
-
}
|
|
1672
|
-
get isWrite() {
|
|
1673
|
-
return (this.flags & 2097155) !== 0;
|
|
1674
|
-
}
|
|
1675
|
-
get isAppend() {
|
|
1676
|
-
return (this.flags & 1024);
|
|
1677
|
-
}
|
|
1678
|
-
get flags() {
|
|
1679
|
-
return this.shared.flags;
|
|
1680
|
-
}
|
|
1681
|
-
set flags(val) {
|
|
1682
|
-
this.shared.flags = val;
|
|
1683
|
-
}
|
|
1684
|
-
get position() {
|
|
1685
|
-
return this.shared.position;
|
|
1686
|
-
}
|
|
1687
|
-
set position(val) {
|
|
1688
|
-
this.shared.position = val;
|
|
1689
|
-
}
|
|
1690
|
-
},
|
|
1691
|
-
FSNode: class {
|
|
1692
|
-
node_ops={};
|
|
1693
|
-
stream_ops={};
|
|
1694
|
-
readMode=292 | 73;
|
|
1695
|
-
writeMode=146;
|
|
1696
|
-
mounted=null;
|
|
1697
|
-
constructor(parent, name, mode, rdev) {
|
|
1698
|
-
if (!parent) {
|
|
1699
|
-
parent = this;
|
|
1700
|
-
}
|
|
1701
|
-
this.parent = parent;
|
|
1702
|
-
this.mount = parent.mount;
|
|
1703
|
-
this.id = FS.nextInode++;
|
|
1704
|
-
this.name = name;
|
|
1705
|
-
this.mode = mode;
|
|
1706
|
-
this.rdev = rdev;
|
|
1707
|
-
this.atime = this.mtime = this.ctime = Date.now();
|
|
1708
|
-
}
|
|
1709
|
-
get read() {
|
|
1710
|
-
return (this.mode & this.readMode) === this.readMode;
|
|
1711
|
-
}
|
|
1712
|
-
set read(val) {
|
|
1713
|
-
val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
|
|
1714
|
-
}
|
|
1715
|
-
get write() {
|
|
1716
|
-
return (this.mode & this.writeMode) === this.writeMode;
|
|
1717
|
-
}
|
|
1718
|
-
set write(val) {
|
|
1719
|
-
val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
|
|
1720
|
-
}
|
|
1721
|
-
get isFolder() {
|
|
1722
|
-
return FS.isDir(this.mode);
|
|
1723
|
-
}
|
|
1724
|
-
get isDevice() {
|
|
1725
|
-
return FS.isChrdev(this.mode);
|
|
1726
|
-
}
|
|
1727
|
-
},
|
|
1728
|
-
lookupPath(path, opts = {}) {
|
|
1729
|
-
if (!path) {
|
|
1730
|
-
throw new FS.ErrnoError(44);
|
|
1731
|
-
}
|
|
1732
|
-
opts.follow_mount ??= true;
|
|
1733
|
-
if (!PATH.isAbs(path)) {
|
|
1734
|
-
path = FS.cwd() + "/" + path;
|
|
1735
|
-
}
|
|
1736
|
-
// limit max consecutive symlinks to 40 (SYMLOOP_MAX).
|
|
1737
|
-
linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
|
|
1738
|
-
// split the absolute path
|
|
1739
|
-
var parts = path.split("/").filter(p => !!p);
|
|
1740
|
-
// start at the root
|
|
1741
|
-
var current = FS.root;
|
|
1742
|
-
var current_path = "/";
|
|
1743
|
-
for (var i = 0; i < parts.length; i++) {
|
|
1744
|
-
var islast = (i === parts.length - 1);
|
|
1745
|
-
if (islast && opts.parent) {
|
|
1746
|
-
// stop resolving
|
|
1747
|
-
break;
|
|
1748
|
-
}
|
|
1749
|
-
if (parts[i] === ".") {
|
|
1750
|
-
continue;
|
|
1751
|
-
}
|
|
1752
|
-
if (parts[i] === "..") {
|
|
1753
|
-
current_path = PATH.dirname(current_path);
|
|
1754
|
-
if (FS.isRoot(current)) {
|
|
1755
|
-
path = current_path + "/" + parts.slice(i + 1).join("/");
|
|
1756
|
-
continue linkloop;
|
|
1757
|
-
} else {
|
|
1758
|
-
current = current.parent;
|
|
1759
|
-
}
|
|
1760
|
-
continue;
|
|
1761
|
-
}
|
|
1762
|
-
current_path = PATH.join2(current_path, parts[i]);
|
|
1763
|
-
try {
|
|
1764
|
-
current = FS.lookupNode(current, parts[i]);
|
|
1765
|
-
} catch (e) {
|
|
1766
|
-
// if noent_okay is true, suppress a ENOENT in the last component
|
|
1767
|
-
// and return an object with an undefined node. This is needed for
|
|
1768
|
-
// resolving symlinks in the path when creating a file.
|
|
1769
|
-
if ((e?.errno === 44) && islast && opts.noent_okay) {
|
|
1770
|
-
return {
|
|
1771
|
-
path: current_path
|
|
1772
|
-
};
|
|
1773
|
-
}
|
|
1774
|
-
throw e;
|
|
1775
|
-
}
|
|
1776
|
-
// jump to the mount's root node if this is a mountpoint
|
|
1777
|
-
if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
|
|
1778
|
-
current = current.mounted.root;
|
|
1779
|
-
}
|
|
1780
|
-
// by default, lookupPath will not follow a symlink if it is the final path component.
|
|
1781
|
-
// setting opts.follow = true will override this behavior.
|
|
1782
|
-
if (FS.isLink(current.mode) && (!islast || opts.follow)) {
|
|
1783
|
-
if (!current.node_ops.readlink) {
|
|
1784
|
-
throw new FS.ErrnoError(52);
|
|
1785
|
-
}
|
|
1786
|
-
var link = current.node_ops.readlink(current);
|
|
1787
|
-
if (!PATH.isAbs(link)) {
|
|
1788
|
-
link = PATH.dirname(current_path) + "/" + link;
|
|
1789
|
-
}
|
|
1790
|
-
path = link + "/" + parts.slice(i + 1).join("/");
|
|
1791
|
-
continue linkloop;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
return {
|
|
1795
|
-
path: current_path,
|
|
1796
|
-
node: current
|
|
1797
|
-
};
|
|
1798
|
-
}
|
|
1799
|
-
throw new FS.ErrnoError(32);
|
|
1800
|
-
},
|
|
1801
|
-
getPath(node) {
|
|
1802
|
-
var path;
|
|
1803
|
-
while (true) {
|
|
1804
|
-
if (FS.isRoot(node)) {
|
|
1805
|
-
var mount = node.mount.mountpoint;
|
|
1806
|
-
if (!path) return mount;
|
|
1807
|
-
return mount[mount.length - 1] !== "/" ? `${mount}/${path}` : mount + path;
|
|
1808
|
-
}
|
|
1809
|
-
path = path ? `${node.name}/${path}` : node.name;
|
|
1810
|
-
node = node.parent;
|
|
1811
|
-
}
|
|
1812
|
-
},
|
|
1813
|
-
hashName(parentid, name) {
|
|
1814
|
-
var hash = 0;
|
|
1815
|
-
for (var i = 0; i < name.length; i++) {
|
|
1816
|
-
hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
|
|
1817
|
-
}
|
|
1818
|
-
return ((parentid + hash) >>> 0) % FS.nameTable.length;
|
|
1819
|
-
},
|
|
1820
|
-
hashAddNode(node) {
|
|
1821
|
-
var hash = FS.hashName(node.parent.id, node.name);
|
|
1822
|
-
node.name_next = FS.nameTable[hash];
|
|
1823
|
-
FS.nameTable[hash] = node;
|
|
1824
|
-
},
|
|
1825
|
-
hashRemoveNode(node) {
|
|
1826
|
-
var hash = FS.hashName(node.parent.id, node.name);
|
|
1827
|
-
if (FS.nameTable[hash] === node) {
|
|
1828
|
-
FS.nameTable[hash] = node.name_next;
|
|
1829
|
-
} else {
|
|
1830
|
-
var current = FS.nameTable[hash];
|
|
1831
|
-
while (current) {
|
|
1832
|
-
if (current.name_next === node) {
|
|
1833
|
-
current.name_next = node.name_next;
|
|
1834
|
-
break;
|
|
1835
|
-
}
|
|
1836
|
-
current = current.name_next;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
},
|
|
1840
|
-
lookupNode(parent, name) {
|
|
1841
|
-
var errCode = FS.mayLookup(parent);
|
|
1842
|
-
if (errCode) {
|
|
1843
|
-
throw new FS.ErrnoError(errCode);
|
|
1844
|
-
}
|
|
1845
|
-
var hash = FS.hashName(parent.id, name);
|
|
1846
|
-
for (var node = FS.nameTable[hash]; node; node = node.name_next) {
|
|
1847
|
-
var nodeName = node.name;
|
|
1848
|
-
if (node.parent.id === parent.id && nodeName === name) {
|
|
1849
|
-
return node;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
// if we failed to find it in the cache, call into the VFS
|
|
1853
|
-
return FS.lookup(parent, name);
|
|
1854
|
-
},
|
|
1855
|
-
createNode(parent, name, mode, rdev) {
|
|
1856
|
-
var node = new FS.FSNode(parent, name, mode, rdev);
|
|
1857
|
-
FS.hashAddNode(node);
|
|
1858
|
-
return node;
|
|
1859
|
-
},
|
|
1860
|
-
destroyNode(node) {
|
|
1861
|
-
FS.hashRemoveNode(node);
|
|
1862
|
-
},
|
|
1863
|
-
isRoot(node) {
|
|
1864
|
-
return node === node.parent;
|
|
1865
|
-
},
|
|
1866
|
-
isMountpoint(node) {
|
|
1867
|
-
return !!node.mounted;
|
|
1868
|
-
},
|
|
1869
|
-
isFile(mode) {
|
|
1870
|
-
return (mode & 61440) === 32768;
|
|
1871
|
-
},
|
|
1872
|
-
isDir(mode) {
|
|
1873
|
-
return (mode & 61440) === 16384;
|
|
1874
|
-
},
|
|
1875
|
-
isLink(mode) {
|
|
1876
|
-
return (mode & 61440) === 40960;
|
|
1877
|
-
},
|
|
1878
|
-
isChrdev(mode) {
|
|
1879
|
-
return (mode & 61440) === 8192;
|
|
1880
|
-
},
|
|
1881
|
-
isBlkdev(mode) {
|
|
1882
|
-
return (mode & 61440) === 24576;
|
|
1883
|
-
},
|
|
1884
|
-
isFIFO(mode) {
|
|
1885
|
-
return (mode & 61440) === 4096;
|
|
1886
|
-
},
|
|
1887
|
-
isSocket(mode) {
|
|
1888
|
-
return (mode & 49152) === 49152;
|
|
1889
|
-
},
|
|
1890
|
-
flagsToPermissionString(flag) {
|
|
1891
|
-
var perms = [ "r", "w", "rw" ][flag & 3];
|
|
1892
|
-
if ((flag & 512)) {
|
|
1893
|
-
perms += "w";
|
|
1894
|
-
}
|
|
1895
|
-
return perms;
|
|
1896
|
-
},
|
|
1897
|
-
nodePermissions(node, perms) {
|
|
1898
|
-
if (FS.ignorePermissions) {
|
|
1899
|
-
return 0;
|
|
1900
|
-
}
|
|
1901
|
-
// return 0 if any user, group or owner bits are set.
|
|
1902
|
-
if (perms.includes("r") && !(node.mode & 292)) {
|
|
1903
|
-
return 2;
|
|
1904
|
-
} else if (perms.includes("w") && !(node.mode & 146)) {
|
|
1905
|
-
return 2;
|
|
1906
|
-
} else if (perms.includes("x") && !(node.mode & 73)) {
|
|
1907
|
-
return 2;
|
|
1908
|
-
}
|
|
1909
|
-
return 0;
|
|
1910
|
-
},
|
|
1911
|
-
mayLookup(dir) {
|
|
1912
|
-
if (!FS.isDir(dir.mode)) return 54;
|
|
1913
|
-
var errCode = FS.nodePermissions(dir, "x");
|
|
1914
|
-
if (errCode) return errCode;
|
|
1915
|
-
if (!dir.node_ops.lookup) return 2;
|
|
1916
|
-
return 0;
|
|
1917
|
-
},
|
|
1918
|
-
mayCreate(dir, name) {
|
|
1919
|
-
if (!FS.isDir(dir.mode)) {
|
|
1920
|
-
return 54;
|
|
1921
|
-
}
|
|
1922
|
-
try {
|
|
1923
|
-
var node = FS.lookupNode(dir, name);
|
|
1924
|
-
return 20;
|
|
1925
|
-
} catch (e) {}
|
|
1926
|
-
return FS.nodePermissions(dir, "wx");
|
|
1927
|
-
},
|
|
1928
|
-
mayDelete(dir, name, isdir) {
|
|
1929
|
-
var node;
|
|
1930
|
-
try {
|
|
1931
|
-
node = FS.lookupNode(dir, name);
|
|
1932
|
-
} catch (e) {
|
|
1933
|
-
return e.errno;
|
|
1934
|
-
}
|
|
1935
|
-
var errCode = FS.nodePermissions(dir, "wx");
|
|
1936
|
-
if (errCode) {
|
|
1937
|
-
return errCode;
|
|
1938
|
-
}
|
|
1939
|
-
if (isdir) {
|
|
1940
|
-
if (!FS.isDir(node.mode)) {
|
|
1941
|
-
return 54;
|
|
1942
|
-
}
|
|
1943
|
-
if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
|
|
1944
|
-
return 10;
|
|
1945
|
-
}
|
|
1946
|
-
} else {
|
|
1947
|
-
if (FS.isDir(node.mode)) {
|
|
1948
|
-
return 31;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
return 0;
|
|
1952
|
-
},
|
|
1953
|
-
mayOpen(node, flags) {
|
|
1954
|
-
if (!node) {
|
|
1955
|
-
return 44;
|
|
1956
|
-
}
|
|
1957
|
-
if (FS.isLink(node.mode)) {
|
|
1958
|
-
return 32;
|
|
1959
|
-
} else if (FS.isDir(node.mode)) {
|
|
1960
|
-
if (FS.flagsToPermissionString(flags) !== "r" || (flags & (512 | 64))) {
|
|
1961
|
-
// TODO: check for O_SEARCH? (== search for dir only)
|
|
1962
|
-
return 31;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
|
|
1966
|
-
},
|
|
1967
|
-
checkOpExists(op, err) {
|
|
1968
|
-
if (!op) {
|
|
1969
|
-
throw new FS.ErrnoError(err);
|
|
1970
|
-
}
|
|
1971
|
-
return op;
|
|
1972
|
-
},
|
|
1973
|
-
MAX_OPEN_FDS: 4096,
|
|
1974
|
-
nextfd() {
|
|
1975
|
-
for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
|
|
1976
|
-
if (!FS.streams[fd]) {
|
|
1977
|
-
return fd;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
throw new FS.ErrnoError(33);
|
|
1981
|
-
},
|
|
1982
|
-
getStreamChecked(fd) {
|
|
1983
|
-
var stream = FS.getStream(fd);
|
|
1984
|
-
if (!stream) {
|
|
1985
|
-
throw new FS.ErrnoError(8);
|
|
1986
|
-
}
|
|
1987
|
-
return stream;
|
|
1988
|
-
},
|
|
1989
|
-
getStream: fd => FS.streams[fd],
|
|
1990
|
-
createStream(stream, fd = -1) {
|
|
1991
|
-
// clone it, so we can return an instance of FSStream
|
|
1992
|
-
stream = Object.assign(new FS.FSStream, stream);
|
|
1993
|
-
if (fd == -1) {
|
|
1994
|
-
fd = FS.nextfd();
|
|
1995
|
-
}
|
|
1996
|
-
stream.fd = fd;
|
|
1997
|
-
FS.streams[fd] = stream;
|
|
1998
|
-
return stream;
|
|
1999
|
-
},
|
|
2000
|
-
closeStream(fd) {
|
|
2001
|
-
FS.streams[fd] = null;
|
|
2002
|
-
},
|
|
2003
|
-
dupStream(origStream, fd = -1) {
|
|
2004
|
-
var stream = FS.createStream(origStream, fd);
|
|
2005
|
-
stream.stream_ops?.dup?.(stream);
|
|
2006
|
-
return stream;
|
|
2007
|
-
},
|
|
2008
|
-
doSetAttr(stream, node, attr) {
|
|
2009
|
-
var setattr = stream?.stream_ops.setattr;
|
|
2010
|
-
var arg = setattr ? stream : node;
|
|
2011
|
-
setattr ??= node.node_ops.setattr;
|
|
2012
|
-
FS.checkOpExists(setattr, 63);
|
|
2013
|
-
setattr(arg, attr);
|
|
2014
|
-
},
|
|
2015
|
-
chrdev_stream_ops: {
|
|
2016
|
-
open(stream) {
|
|
2017
|
-
var device = FS.getDevice(stream.node.rdev);
|
|
2018
|
-
// override node's stream ops with the device's
|
|
2019
|
-
stream.stream_ops = device.stream_ops;
|
|
2020
|
-
// forward the open call
|
|
2021
|
-
stream.stream_ops.open?.(stream);
|
|
2022
|
-
},
|
|
2023
|
-
llseek() {
|
|
2024
|
-
throw new FS.ErrnoError(70);
|
|
2025
|
-
}
|
|
2026
|
-
},
|
|
2027
|
-
major: dev => ((dev) >> 8),
|
|
2028
|
-
minor: dev => ((dev) & 255),
|
|
2029
|
-
makedev: (ma, mi) => ((ma) << 8 | (mi)),
|
|
2030
|
-
registerDevice(dev, ops) {
|
|
2031
|
-
FS.devices[dev] = {
|
|
2032
|
-
stream_ops: ops
|
|
2033
|
-
};
|
|
2034
|
-
},
|
|
2035
|
-
getDevice: dev => FS.devices[dev],
|
|
2036
|
-
getMounts(mount) {
|
|
2037
|
-
var mounts = [];
|
|
2038
|
-
var check = [ mount ];
|
|
2039
|
-
while (check.length) {
|
|
2040
|
-
var m = check.pop();
|
|
2041
|
-
mounts.push(m);
|
|
2042
|
-
check.push(...m.mounts);
|
|
2043
|
-
}
|
|
2044
|
-
return mounts;
|
|
2045
|
-
},
|
|
2046
|
-
syncfs(populate, callback) {
|
|
2047
|
-
if (typeof populate == "function") {
|
|
2048
|
-
callback = populate;
|
|
2049
|
-
populate = false;
|
|
2050
|
-
}
|
|
2051
|
-
FS.syncFSRequests++;
|
|
2052
|
-
if (FS.syncFSRequests > 1) {
|
|
2053
|
-
err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);
|
|
2054
|
-
}
|
|
2055
|
-
var mounts = FS.getMounts(FS.root.mount);
|
|
2056
|
-
var completed = 0;
|
|
2057
|
-
function doCallback(errCode) {
|
|
2058
|
-
FS.syncFSRequests--;
|
|
2059
|
-
return callback(errCode);
|
|
2060
|
-
}
|
|
2061
|
-
function done(errCode) {
|
|
2062
|
-
if (errCode) {
|
|
2063
|
-
if (!done.errored) {
|
|
2064
|
-
done.errored = true;
|
|
2065
|
-
return doCallback(errCode);
|
|
2066
|
-
}
|
|
2067
|
-
return;
|
|
2068
|
-
}
|
|
2069
|
-
if (++completed >= mounts.length) {
|
|
2070
|
-
doCallback(null);
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
// sync all mounts
|
|
2074
|
-
mounts.forEach(mount => {
|
|
2075
|
-
if (!mount.type.syncfs) {
|
|
2076
|
-
return done(null);
|
|
2077
|
-
}
|
|
2078
|
-
mount.type.syncfs(mount, populate, done);
|
|
2079
|
-
});
|
|
2080
|
-
},
|
|
2081
|
-
mount(type, opts, mountpoint) {
|
|
2082
|
-
var root = mountpoint === "/";
|
|
2083
|
-
var pseudo = !mountpoint;
|
|
2084
|
-
var node;
|
|
2085
|
-
if (root && FS.root) {
|
|
2086
|
-
throw new FS.ErrnoError(10);
|
|
2087
|
-
} else if (!root && !pseudo) {
|
|
2088
|
-
var lookup = FS.lookupPath(mountpoint, {
|
|
2089
|
-
follow_mount: false
|
|
2090
|
-
});
|
|
2091
|
-
mountpoint = lookup.path;
|
|
2092
|
-
// use the absolute path
|
|
2093
|
-
node = lookup.node;
|
|
2094
|
-
if (FS.isMountpoint(node)) {
|
|
2095
|
-
throw new FS.ErrnoError(10);
|
|
2096
|
-
}
|
|
2097
|
-
if (!FS.isDir(node.mode)) {
|
|
2098
|
-
throw new FS.ErrnoError(54);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
var mount = {
|
|
2102
|
-
type,
|
|
2103
|
-
opts,
|
|
2104
|
-
mountpoint,
|
|
2105
|
-
mounts: []
|
|
2106
|
-
};
|
|
2107
|
-
// create a root node for the fs
|
|
2108
|
-
var mountRoot = type.mount(mount);
|
|
2109
|
-
mountRoot.mount = mount;
|
|
2110
|
-
mount.root = mountRoot;
|
|
2111
|
-
if (root) {
|
|
2112
|
-
FS.root = mountRoot;
|
|
2113
|
-
} else if (node) {
|
|
2114
|
-
// set as a mountpoint
|
|
2115
|
-
node.mounted = mount;
|
|
2116
|
-
// add the new mount to the current mount's children
|
|
2117
|
-
if (node.mount) {
|
|
2118
|
-
node.mount.mounts.push(mount);
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
return mountRoot;
|
|
2122
|
-
},
|
|
2123
|
-
unmount(mountpoint) {
|
|
2124
|
-
var lookup = FS.lookupPath(mountpoint, {
|
|
2125
|
-
follow_mount: false
|
|
2126
|
-
});
|
|
2127
|
-
if (!FS.isMountpoint(lookup.node)) {
|
|
2128
|
-
throw new FS.ErrnoError(28);
|
|
2129
|
-
}
|
|
2130
|
-
// destroy the nodes for this mount, and all its child mounts
|
|
2131
|
-
var node = lookup.node;
|
|
2132
|
-
var mount = node.mounted;
|
|
2133
|
-
var mounts = FS.getMounts(mount);
|
|
2134
|
-
Object.keys(FS.nameTable).forEach(hash => {
|
|
2135
|
-
var current = FS.nameTable[hash];
|
|
2136
|
-
while (current) {
|
|
2137
|
-
var next = current.name_next;
|
|
2138
|
-
if (mounts.includes(current.mount)) {
|
|
2139
|
-
FS.destroyNode(current);
|
|
2140
|
-
}
|
|
2141
|
-
current = next;
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
// no longer a mountpoint
|
|
2145
|
-
node.mounted = null;
|
|
2146
|
-
// remove this mount from the child mounts
|
|
2147
|
-
var idx = node.mount.mounts.indexOf(mount);
|
|
2148
|
-
node.mount.mounts.splice(idx, 1);
|
|
2149
|
-
},
|
|
2150
|
-
lookup(parent, name) {
|
|
2151
|
-
return parent.node_ops.lookup(parent, name);
|
|
2152
|
-
},
|
|
2153
|
-
mknod(path, mode, dev) {
|
|
2154
|
-
var lookup = FS.lookupPath(path, {
|
|
2155
|
-
parent: true
|
|
2156
|
-
});
|
|
2157
|
-
var parent = lookup.node;
|
|
2158
|
-
var name = PATH.basename(path);
|
|
2159
|
-
if (!name) {
|
|
2160
|
-
throw new FS.ErrnoError(28);
|
|
2161
|
-
}
|
|
2162
|
-
if (name === "." || name === "..") {
|
|
2163
|
-
throw new FS.ErrnoError(20);
|
|
2164
|
-
}
|
|
2165
|
-
var errCode = FS.mayCreate(parent, name);
|
|
2166
|
-
if (errCode) {
|
|
2167
|
-
throw new FS.ErrnoError(errCode);
|
|
2168
|
-
}
|
|
2169
|
-
if (!parent.node_ops.mknod) {
|
|
2170
|
-
throw new FS.ErrnoError(63);
|
|
2171
|
-
}
|
|
2172
|
-
return parent.node_ops.mknod(parent, name, mode, dev);
|
|
2173
|
-
},
|
|
2174
|
-
statfs(path) {
|
|
2175
|
-
return FS.statfsNode(FS.lookupPath(path, {
|
|
2176
|
-
follow: true
|
|
2177
|
-
}).node);
|
|
2178
|
-
},
|
|
2179
|
-
statfsStream(stream) {
|
|
2180
|
-
// We keep a separate statfsStream function because noderawfs overrides
|
|
2181
|
-
// it. In noderawfs, stream.node is sometimes null. Instead, we need to
|
|
2182
|
-
// look at stream.path.
|
|
2183
|
-
return FS.statfsNode(stream.node);
|
|
2184
|
-
},
|
|
2185
|
-
statfsNode(node) {
|
|
2186
|
-
// NOTE: None of the defaults here are true. We're just returning safe and
|
|
2187
|
-
// sane values. Currently nodefs and rawfs replace these defaults,
|
|
2188
|
-
// other file systems leave them alone.
|
|
2189
|
-
var rtn = {
|
|
2190
|
-
bsize: 4096,
|
|
2191
|
-
frsize: 4096,
|
|
2192
|
-
blocks: 1e6,
|
|
2193
|
-
bfree: 5e5,
|
|
2194
|
-
bavail: 5e5,
|
|
2195
|
-
files: FS.nextInode,
|
|
2196
|
-
ffree: FS.nextInode - 1,
|
|
2197
|
-
fsid: 42,
|
|
2198
|
-
flags: 2,
|
|
2199
|
-
namelen: 255
|
|
2200
|
-
};
|
|
2201
|
-
if (node.node_ops.statfs) {
|
|
2202
|
-
Object.assign(rtn, node.node_ops.statfs(node.mount.opts.root));
|
|
2203
|
-
}
|
|
2204
|
-
return rtn;
|
|
2205
|
-
},
|
|
2206
|
-
create(path, mode = 438) {
|
|
2207
|
-
mode &= 4095;
|
|
2208
|
-
mode |= 32768;
|
|
2209
|
-
return FS.mknod(path, mode, 0);
|
|
2210
|
-
},
|
|
2211
|
-
mkdir(path, mode = 511) {
|
|
2212
|
-
mode &= 511 | 512;
|
|
2213
|
-
mode |= 16384;
|
|
2214
|
-
return FS.mknod(path, mode, 0);
|
|
2215
|
-
},
|
|
2216
|
-
mkdirTree(path, mode) {
|
|
2217
|
-
var dirs = path.split("/");
|
|
2218
|
-
var d = "";
|
|
2219
|
-
for (var dir of dirs) {
|
|
2220
|
-
if (!dir) continue;
|
|
2221
|
-
if (d || PATH.isAbs(path)) d += "/";
|
|
2222
|
-
d += dir;
|
|
2223
|
-
try {
|
|
2224
|
-
FS.mkdir(d, mode);
|
|
2225
|
-
} catch (e) {
|
|
2226
|
-
if (e.errno != 20) throw e;
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
},
|
|
2230
|
-
mkdev(path, mode, dev) {
|
|
2231
|
-
if (typeof dev == "undefined") {
|
|
2232
|
-
dev = mode;
|
|
2233
|
-
mode = 438;
|
|
2234
|
-
}
|
|
2235
|
-
mode |= 8192;
|
|
2236
|
-
return FS.mknod(path, mode, dev);
|
|
2237
|
-
},
|
|
2238
|
-
symlink(oldpath, newpath) {
|
|
2239
|
-
if (!PATH_FS.resolve(oldpath)) {
|
|
2240
|
-
throw new FS.ErrnoError(44);
|
|
2241
|
-
}
|
|
2242
|
-
var lookup = FS.lookupPath(newpath, {
|
|
2243
|
-
parent: true
|
|
2244
|
-
});
|
|
2245
|
-
var parent = lookup.node;
|
|
2246
|
-
if (!parent) {
|
|
2247
|
-
throw new FS.ErrnoError(44);
|
|
2248
|
-
}
|
|
2249
|
-
var newname = PATH.basename(newpath);
|
|
2250
|
-
var errCode = FS.mayCreate(parent, newname);
|
|
2251
|
-
if (errCode) {
|
|
2252
|
-
throw new FS.ErrnoError(errCode);
|
|
2253
|
-
}
|
|
2254
|
-
if (!parent.node_ops.symlink) {
|
|
2255
|
-
throw new FS.ErrnoError(63);
|
|
2256
|
-
}
|
|
2257
|
-
return parent.node_ops.symlink(parent, newname, oldpath);
|
|
2258
|
-
},
|
|
2259
|
-
rename(old_path, new_path) {
|
|
2260
|
-
var old_dirname = PATH.dirname(old_path);
|
|
2261
|
-
var new_dirname = PATH.dirname(new_path);
|
|
2262
|
-
var old_name = PATH.basename(old_path);
|
|
2263
|
-
var new_name = PATH.basename(new_path);
|
|
2264
|
-
// parents must exist
|
|
2265
|
-
var lookup, old_dir, new_dir;
|
|
2266
|
-
// let the errors from non existent directories percolate up
|
|
2267
|
-
lookup = FS.lookupPath(old_path, {
|
|
2268
|
-
parent: true
|
|
2269
|
-
});
|
|
2270
|
-
old_dir = lookup.node;
|
|
2271
|
-
lookup = FS.lookupPath(new_path, {
|
|
2272
|
-
parent: true
|
|
2273
|
-
});
|
|
2274
|
-
new_dir = lookup.node;
|
|
2275
|
-
if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
|
|
2276
|
-
// need to be part of the same mount
|
|
2277
|
-
if (old_dir.mount !== new_dir.mount) {
|
|
2278
|
-
throw new FS.ErrnoError(75);
|
|
2279
|
-
}
|
|
2280
|
-
// source must exist
|
|
2281
|
-
var old_node = FS.lookupNode(old_dir, old_name);
|
|
2282
|
-
// old path should not be an ancestor of the new path
|
|
2283
|
-
var relative = PATH_FS.relative(old_path, new_dirname);
|
|
2284
|
-
if (relative.charAt(0) !== ".") {
|
|
2285
|
-
throw new FS.ErrnoError(28);
|
|
2286
|
-
}
|
|
2287
|
-
// new path should not be an ancestor of the old path
|
|
2288
|
-
relative = PATH_FS.relative(new_path, old_dirname);
|
|
2289
|
-
if (relative.charAt(0) !== ".") {
|
|
2290
|
-
throw new FS.ErrnoError(55);
|
|
2291
|
-
}
|
|
2292
|
-
// see if the new path already exists
|
|
2293
|
-
var new_node;
|
|
2294
|
-
try {
|
|
2295
|
-
new_node = FS.lookupNode(new_dir, new_name);
|
|
2296
|
-
} catch (e) {}
|
|
2297
|
-
// early out if nothing needs to change
|
|
2298
|
-
if (old_node === new_node) {
|
|
2299
|
-
return;
|
|
2300
|
-
}
|
|
2301
|
-
// we'll need to delete the old entry
|
|
2302
|
-
var isdir = FS.isDir(old_node.mode);
|
|
2303
|
-
var errCode = FS.mayDelete(old_dir, old_name, isdir);
|
|
2304
|
-
if (errCode) {
|
|
2305
|
-
throw new FS.ErrnoError(errCode);
|
|
2306
|
-
}
|
|
2307
|
-
// need delete permissions if we'll be overwriting.
|
|
2308
|
-
// need create permissions if new doesn't already exist.
|
|
2309
|
-
errCode = new_node ? FS.mayDelete(new_dir, new_name, isdir) : FS.mayCreate(new_dir, new_name);
|
|
2310
|
-
if (errCode) {
|
|
2311
|
-
throw new FS.ErrnoError(errCode);
|
|
2312
|
-
}
|
|
2313
|
-
if (!old_dir.node_ops.rename) {
|
|
2314
|
-
throw new FS.ErrnoError(63);
|
|
2315
|
-
}
|
|
2316
|
-
if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
|
|
2317
|
-
throw new FS.ErrnoError(10);
|
|
2318
|
-
}
|
|
2319
|
-
// if we are going to change the parent, check write permissions
|
|
2320
|
-
if (new_dir !== old_dir) {
|
|
2321
|
-
errCode = FS.nodePermissions(old_dir, "w");
|
|
2322
|
-
if (errCode) {
|
|
2323
|
-
throw new FS.ErrnoError(errCode);
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
// remove the node from the lookup hash
|
|
2327
|
-
FS.hashRemoveNode(old_node);
|
|
2328
|
-
// do the underlying fs rename
|
|
2329
|
-
try {
|
|
2330
|
-
old_dir.node_ops.rename(old_node, new_dir, new_name);
|
|
2331
|
-
// update old node (we do this here to avoid each backend
|
|
2332
|
-
// needing to)
|
|
2333
|
-
old_node.parent = new_dir;
|
|
2334
|
-
} catch (e) {
|
|
2335
|
-
throw e;
|
|
2336
|
-
} finally {
|
|
2337
|
-
// add the node back to the hash (in case node_ops.rename
|
|
2338
|
-
// changed its name)
|
|
2339
|
-
FS.hashAddNode(old_node);
|
|
2340
|
-
}
|
|
2341
|
-
},
|
|
2342
|
-
rmdir(path) {
|
|
2343
|
-
var lookup = FS.lookupPath(path, {
|
|
2344
|
-
parent: true
|
|
2345
|
-
});
|
|
2346
|
-
var parent = lookup.node;
|
|
2347
|
-
var name = PATH.basename(path);
|
|
2348
|
-
var node = FS.lookupNode(parent, name);
|
|
2349
|
-
var errCode = FS.mayDelete(parent, name, true);
|
|
2350
|
-
if (errCode) {
|
|
2351
|
-
throw new FS.ErrnoError(errCode);
|
|
2352
|
-
}
|
|
2353
|
-
if (!parent.node_ops.rmdir) {
|
|
2354
|
-
throw new FS.ErrnoError(63);
|
|
2355
|
-
}
|
|
2356
|
-
if (FS.isMountpoint(node)) {
|
|
2357
|
-
throw new FS.ErrnoError(10);
|
|
2358
|
-
}
|
|
2359
|
-
parent.node_ops.rmdir(parent, name);
|
|
2360
|
-
FS.destroyNode(node);
|
|
2361
|
-
},
|
|
2362
|
-
readdir(path) {
|
|
2363
|
-
var lookup = FS.lookupPath(path, {
|
|
2364
|
-
follow: true
|
|
2365
|
-
});
|
|
2366
|
-
var node = lookup.node;
|
|
2367
|
-
var readdir = FS.checkOpExists(node.node_ops.readdir, 54);
|
|
2368
|
-
return readdir(node);
|
|
2369
|
-
},
|
|
2370
|
-
unlink(path) {
|
|
2371
|
-
var lookup = FS.lookupPath(path, {
|
|
2372
|
-
parent: true
|
|
2373
|
-
});
|
|
2374
|
-
var parent = lookup.node;
|
|
2375
|
-
if (!parent) {
|
|
2376
|
-
throw new FS.ErrnoError(44);
|
|
2377
|
-
}
|
|
2378
|
-
var name = PATH.basename(path);
|
|
2379
|
-
var node = FS.lookupNode(parent, name);
|
|
2380
|
-
var errCode = FS.mayDelete(parent, name, false);
|
|
2381
|
-
if (errCode) {
|
|
2382
|
-
// According to POSIX, we should map EISDIR to EPERM, but
|
|
2383
|
-
// we instead do what Linux does (and we must, as we use
|
|
2384
|
-
// the musl linux libc).
|
|
2385
|
-
throw new FS.ErrnoError(errCode);
|
|
2386
|
-
}
|
|
2387
|
-
if (!parent.node_ops.unlink) {
|
|
2388
|
-
throw new FS.ErrnoError(63);
|
|
2389
|
-
}
|
|
2390
|
-
if (FS.isMountpoint(node)) {
|
|
2391
|
-
throw new FS.ErrnoError(10);
|
|
2392
|
-
}
|
|
2393
|
-
parent.node_ops.unlink(parent, name);
|
|
2394
|
-
FS.destroyNode(node);
|
|
2395
|
-
},
|
|
2396
|
-
readlink(path) {
|
|
2397
|
-
var lookup = FS.lookupPath(path);
|
|
2398
|
-
var link = lookup.node;
|
|
2399
|
-
if (!link) {
|
|
2400
|
-
throw new FS.ErrnoError(44);
|
|
2401
|
-
}
|
|
2402
|
-
if (!link.node_ops.readlink) {
|
|
2403
|
-
throw new FS.ErrnoError(28);
|
|
2404
|
-
}
|
|
2405
|
-
return link.node_ops.readlink(link);
|
|
2406
|
-
},
|
|
2407
|
-
stat(path, dontFollow) {
|
|
2408
|
-
var lookup = FS.lookupPath(path, {
|
|
2409
|
-
follow: !dontFollow
|
|
2410
|
-
});
|
|
2411
|
-
var node = lookup.node;
|
|
2412
|
-
var getattr = FS.checkOpExists(node.node_ops.getattr, 63);
|
|
2413
|
-
return getattr(node);
|
|
2414
|
-
},
|
|
2415
|
-
fstat(fd) {
|
|
2416
|
-
var stream = FS.getStreamChecked(fd);
|
|
2417
|
-
var node = stream.node;
|
|
2418
|
-
var getattr = stream.stream_ops.getattr;
|
|
2419
|
-
var arg = getattr ? stream : node;
|
|
2420
|
-
getattr ??= node.node_ops.getattr;
|
|
2421
|
-
FS.checkOpExists(getattr, 63);
|
|
2422
|
-
return getattr(arg);
|
|
2423
|
-
},
|
|
2424
|
-
lstat(path) {
|
|
2425
|
-
return FS.stat(path, true);
|
|
2426
|
-
},
|
|
2427
|
-
doChmod(stream, node, mode, dontFollow) {
|
|
2428
|
-
FS.doSetAttr(stream, node, {
|
|
2429
|
-
mode: (mode & 4095) | (node.mode & ~4095),
|
|
2430
|
-
ctime: Date.now(),
|
|
2431
|
-
dontFollow
|
|
2432
|
-
});
|
|
2433
|
-
},
|
|
2434
|
-
chmod(path, mode, dontFollow) {
|
|
2435
|
-
var node;
|
|
2436
|
-
if (typeof path == "string") {
|
|
2437
|
-
var lookup = FS.lookupPath(path, {
|
|
2438
|
-
follow: !dontFollow
|
|
2439
|
-
});
|
|
2440
|
-
node = lookup.node;
|
|
2441
|
-
} else {
|
|
2442
|
-
node = path;
|
|
2443
|
-
}
|
|
2444
|
-
FS.doChmod(null, node, mode, dontFollow);
|
|
2445
|
-
},
|
|
2446
|
-
lchmod(path, mode) {
|
|
2447
|
-
FS.chmod(path, mode, true);
|
|
2448
|
-
},
|
|
2449
|
-
fchmod(fd, mode) {
|
|
2450
|
-
var stream = FS.getStreamChecked(fd);
|
|
2451
|
-
FS.doChmod(stream, stream.node, mode, false);
|
|
2452
|
-
},
|
|
2453
|
-
doChown(stream, node, dontFollow) {
|
|
2454
|
-
FS.doSetAttr(stream, node, {
|
|
2455
|
-
timestamp: Date.now(),
|
|
2456
|
-
dontFollow
|
|
2457
|
-
});
|
|
2458
|
-
},
|
|
2459
|
-
chown(path, uid, gid, dontFollow) {
|
|
2460
|
-
var node;
|
|
2461
|
-
if (typeof path == "string") {
|
|
2462
|
-
var lookup = FS.lookupPath(path, {
|
|
2463
|
-
follow: !dontFollow
|
|
2464
|
-
});
|
|
2465
|
-
node = lookup.node;
|
|
2466
|
-
} else {
|
|
2467
|
-
node = path;
|
|
2468
|
-
}
|
|
2469
|
-
FS.doChown(null, node, dontFollow);
|
|
2470
|
-
},
|
|
2471
|
-
lchown(path, uid, gid) {
|
|
2472
|
-
FS.chown(path, uid, gid, true);
|
|
2473
|
-
},
|
|
2474
|
-
fchown(fd, uid, gid) {
|
|
2475
|
-
var stream = FS.getStreamChecked(fd);
|
|
2476
|
-
FS.doChown(stream, stream.node, false);
|
|
2477
|
-
},
|
|
2478
|
-
doTruncate(stream, node, len) {
|
|
2479
|
-
if (FS.isDir(node.mode)) {
|
|
2480
|
-
throw new FS.ErrnoError(31);
|
|
2481
|
-
}
|
|
2482
|
-
if (!FS.isFile(node.mode)) {
|
|
2483
|
-
throw new FS.ErrnoError(28);
|
|
2484
|
-
}
|
|
2485
|
-
var errCode = FS.nodePermissions(node, "w");
|
|
2486
|
-
if (errCode) {
|
|
2487
|
-
throw new FS.ErrnoError(errCode);
|
|
2488
|
-
}
|
|
2489
|
-
FS.doSetAttr(stream, node, {
|
|
2490
|
-
size: len,
|
|
2491
|
-
timestamp: Date.now()
|
|
2492
|
-
});
|
|
2493
|
-
},
|
|
2494
|
-
truncate(path, len) {
|
|
2495
|
-
if (len < 0) {
|
|
2496
|
-
throw new FS.ErrnoError(28);
|
|
2497
|
-
}
|
|
2498
|
-
var node;
|
|
2499
|
-
if (typeof path == "string") {
|
|
2500
|
-
var lookup = FS.lookupPath(path, {
|
|
2501
|
-
follow: true
|
|
2502
|
-
});
|
|
2503
|
-
node = lookup.node;
|
|
2504
|
-
} else {
|
|
2505
|
-
node = path;
|
|
2506
|
-
}
|
|
2507
|
-
FS.doTruncate(null, node, len);
|
|
2508
|
-
},
|
|
2509
|
-
ftruncate(fd, len) {
|
|
2510
|
-
var stream = FS.getStreamChecked(fd);
|
|
2511
|
-
if (len < 0 || (stream.flags & 2097155) === 0) {
|
|
2512
|
-
throw new FS.ErrnoError(28);
|
|
2513
|
-
}
|
|
2514
|
-
FS.doTruncate(stream, stream.node, len);
|
|
2515
|
-
},
|
|
2516
|
-
utime(path, atime, mtime) {
|
|
2517
|
-
var lookup = FS.lookupPath(path, {
|
|
2518
|
-
follow: true
|
|
2519
|
-
});
|
|
2520
|
-
var node = lookup.node;
|
|
2521
|
-
var setattr = FS.checkOpExists(node.node_ops.setattr, 63);
|
|
2522
|
-
setattr(node, {
|
|
2523
|
-
atime,
|
|
2524
|
-
mtime
|
|
2525
|
-
});
|
|
2526
|
-
},
|
|
2527
|
-
open(path, flags, mode = 438) {
|
|
2528
|
-
if (path === "") {
|
|
2529
|
-
throw new FS.ErrnoError(44);
|
|
2530
|
-
}
|
|
2531
|
-
flags = typeof flags == "string" ? FS_modeStringToFlags(flags) : flags;
|
|
2532
|
-
if ((flags & 64)) {
|
|
2533
|
-
mode = (mode & 4095) | 32768;
|
|
2534
|
-
} else {
|
|
2535
|
-
mode = 0;
|
|
2536
|
-
}
|
|
2537
|
-
var node;
|
|
2538
|
-
var isDirPath;
|
|
2539
|
-
if (typeof path == "object") {
|
|
2540
|
-
node = path;
|
|
2541
|
-
} else {
|
|
2542
|
-
isDirPath = path.endsWith("/");
|
|
2543
|
-
// noent_okay makes it so that if the final component of the path
|
|
2544
|
-
// doesn't exist, lookupPath returns `node: undefined`. `path` will be
|
|
2545
|
-
// updated to point to the target of all symlinks.
|
|
2546
|
-
var lookup = FS.lookupPath(path, {
|
|
2547
|
-
follow: !(flags & 131072),
|
|
2548
|
-
noent_okay: true
|
|
2549
|
-
});
|
|
2550
|
-
node = lookup.node;
|
|
2551
|
-
path = lookup.path;
|
|
2552
|
-
}
|
|
2553
|
-
// perhaps we need to create the node
|
|
2554
|
-
var created = false;
|
|
2555
|
-
if ((flags & 64)) {
|
|
2556
|
-
if (node) {
|
|
2557
|
-
// if O_CREAT and O_EXCL are set, error out if the node already exists
|
|
2558
|
-
if ((flags & 128)) {
|
|
2559
|
-
throw new FS.ErrnoError(20);
|
|
2560
|
-
}
|
|
2561
|
-
} else if (isDirPath) {
|
|
2562
|
-
throw new FS.ErrnoError(31);
|
|
2563
|
-
} else {
|
|
2564
|
-
// node doesn't exist, try to create it
|
|
2565
|
-
// Ignore the permission bits here to ensure we can `open` this new
|
|
2566
|
-
// file below. We use chmod below the apply the permissions once the
|
|
2567
|
-
// file is open.
|
|
2568
|
-
node = FS.mknod(path, mode | 511, 0);
|
|
2569
|
-
created = true;
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
if (!node) {
|
|
2573
|
-
throw new FS.ErrnoError(44);
|
|
2574
|
-
}
|
|
2575
|
-
// can't truncate a device
|
|
2576
|
-
if (FS.isChrdev(node.mode)) {
|
|
2577
|
-
flags &= ~512;
|
|
2578
|
-
}
|
|
2579
|
-
// if asked only for a directory, then this must be one
|
|
2580
|
-
if ((flags & 65536) && !FS.isDir(node.mode)) {
|
|
2581
|
-
throw new FS.ErrnoError(54);
|
|
2582
|
-
}
|
|
2583
|
-
// check permissions, if this is not a file we just created now (it is ok to
|
|
2584
|
-
// create and write to a file with read-only permissions; it is read-only
|
|
2585
|
-
// for later use)
|
|
2586
|
-
if (!created) {
|
|
2587
|
-
var errCode = FS.mayOpen(node, flags);
|
|
2588
|
-
if (errCode) {
|
|
2589
|
-
throw new FS.ErrnoError(errCode);
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
// do truncation if necessary
|
|
2593
|
-
if ((flags & 512) && !created) {
|
|
2594
|
-
FS.truncate(node, 0);
|
|
2595
|
-
}
|
|
2596
|
-
// we've already handled these, don't pass down to the underlying vfs
|
|
2597
|
-
flags &= ~(128 | 512 | 131072);
|
|
2598
|
-
// register the stream with the filesystem
|
|
2599
|
-
var stream = FS.createStream({
|
|
2600
|
-
node,
|
|
2601
|
-
path: FS.getPath(node),
|
|
2602
|
-
// we want the absolute path to the node
|
|
2603
|
-
flags,
|
|
2604
|
-
seekable: true,
|
|
2605
|
-
position: 0,
|
|
2606
|
-
stream_ops: node.stream_ops,
|
|
2607
|
-
// used by the file family libc calls (fopen, fwrite, ferror, etc.)
|
|
2608
|
-
ungotten: [],
|
|
2609
|
-
error: false
|
|
2610
|
-
});
|
|
2611
|
-
// call the new stream's open function
|
|
2612
|
-
if (stream.stream_ops.open) {
|
|
2613
|
-
stream.stream_ops.open(stream);
|
|
2614
|
-
}
|
|
2615
|
-
if (created) {
|
|
2616
|
-
FS.chmod(node, mode & 511);
|
|
2617
|
-
}
|
|
2618
|
-
if (Module["logReadFiles"] && !(flags & 1)) {
|
|
2619
|
-
if (!(path in FS.readFiles)) {
|
|
2620
|
-
FS.readFiles[path] = 1;
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
return stream;
|
|
2624
|
-
},
|
|
2625
|
-
close(stream) {
|
|
2626
|
-
if (FS.isClosed(stream)) {
|
|
2627
|
-
throw new FS.ErrnoError(8);
|
|
2628
|
-
}
|
|
2629
|
-
if (stream.getdents) stream.getdents = null;
|
|
2630
|
-
// free readdir state
|
|
2631
|
-
try {
|
|
2632
|
-
if (stream.stream_ops.close) {
|
|
2633
|
-
stream.stream_ops.close(stream);
|
|
2634
|
-
}
|
|
2635
|
-
} catch (e) {
|
|
2636
|
-
throw e;
|
|
2637
|
-
} finally {
|
|
2638
|
-
FS.closeStream(stream.fd);
|
|
2639
|
-
}
|
|
2640
|
-
stream.fd = null;
|
|
2641
|
-
},
|
|
2642
|
-
isClosed(stream) {
|
|
2643
|
-
return stream.fd === null;
|
|
2644
|
-
},
|
|
2645
|
-
llseek(stream, offset, whence) {
|
|
2646
|
-
if (FS.isClosed(stream)) {
|
|
2647
|
-
throw new FS.ErrnoError(8);
|
|
2648
|
-
}
|
|
2649
|
-
if (!stream.seekable || !stream.stream_ops.llseek) {
|
|
2650
|
-
throw new FS.ErrnoError(70);
|
|
2651
|
-
}
|
|
2652
|
-
if (whence != 0 && whence != 1 && whence != 2) {
|
|
2653
|
-
throw new FS.ErrnoError(28);
|
|
2654
|
-
}
|
|
2655
|
-
stream.position = stream.stream_ops.llseek(stream, offset, whence);
|
|
2656
|
-
stream.ungotten = [];
|
|
2657
|
-
return stream.position;
|
|
2658
|
-
},
|
|
2659
|
-
read(stream, buffer, offset, length, position) {
|
|
2660
|
-
if (length < 0 || position < 0) {
|
|
2661
|
-
throw new FS.ErrnoError(28);
|
|
2662
|
-
}
|
|
2663
|
-
if (FS.isClosed(stream)) {
|
|
2664
|
-
throw new FS.ErrnoError(8);
|
|
2665
|
-
}
|
|
2666
|
-
if ((stream.flags & 2097155) === 1) {
|
|
2667
|
-
throw new FS.ErrnoError(8);
|
|
2668
|
-
}
|
|
2669
|
-
if (FS.isDir(stream.node.mode)) {
|
|
2670
|
-
throw new FS.ErrnoError(31);
|
|
2671
|
-
}
|
|
2672
|
-
if (!stream.stream_ops.read) {
|
|
2673
|
-
throw new FS.ErrnoError(28);
|
|
2674
|
-
}
|
|
2675
|
-
var seeking = typeof position != "undefined";
|
|
2676
|
-
if (!seeking) {
|
|
2677
|
-
position = stream.position;
|
|
2678
|
-
} else if (!stream.seekable) {
|
|
2679
|
-
throw new FS.ErrnoError(70);
|
|
2680
|
-
}
|
|
2681
|
-
var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
|
|
2682
|
-
if (!seeking) stream.position += bytesRead;
|
|
2683
|
-
return bytesRead;
|
|
2684
|
-
},
|
|
2685
|
-
write(stream, buffer, offset, length, position, canOwn) {
|
|
2686
|
-
if (length < 0 || position < 0) {
|
|
2687
|
-
throw new FS.ErrnoError(28);
|
|
2688
|
-
}
|
|
2689
|
-
if (FS.isClosed(stream)) {
|
|
2690
|
-
throw new FS.ErrnoError(8);
|
|
2691
|
-
}
|
|
2692
|
-
if ((stream.flags & 2097155) === 0) {
|
|
2693
|
-
throw new FS.ErrnoError(8);
|
|
2694
|
-
}
|
|
2695
|
-
if (FS.isDir(stream.node.mode)) {
|
|
2696
|
-
throw new FS.ErrnoError(31);
|
|
2697
|
-
}
|
|
2698
|
-
if (!stream.stream_ops.write) {
|
|
2699
|
-
throw new FS.ErrnoError(28);
|
|
2700
|
-
}
|
|
2701
|
-
if (stream.seekable && stream.flags & 1024) {
|
|
2702
|
-
// seek to the end before writing in append mode
|
|
2703
|
-
FS.llseek(stream, 0, 2);
|
|
2704
|
-
}
|
|
2705
|
-
var seeking = typeof position != "undefined";
|
|
2706
|
-
if (!seeking) {
|
|
2707
|
-
position = stream.position;
|
|
2708
|
-
} else if (!stream.seekable) {
|
|
2709
|
-
throw new FS.ErrnoError(70);
|
|
2710
|
-
}
|
|
2711
|
-
var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
|
|
2712
|
-
if (!seeking) stream.position += bytesWritten;
|
|
2713
|
-
return bytesWritten;
|
|
2714
|
-
},
|
|
2715
|
-
mmap(stream, length, position, prot, flags) {
|
|
2716
|
-
// User requests writing to file (prot & PROT_WRITE != 0).
|
|
2717
|
-
// Checking if we have permissions to write to the file unless
|
|
2718
|
-
// MAP_PRIVATE flag is set. According to POSIX spec it is possible
|
|
2719
|
-
// to write to file opened in read-only mode with MAP_PRIVATE flag,
|
|
2720
|
-
// as all modifications will be visible only in the memory of
|
|
2721
|
-
// the current process.
|
|
2722
|
-
if ((prot & 2) !== 0 && (flags & 2) === 0 && (stream.flags & 2097155) !== 2) {
|
|
2723
|
-
throw new FS.ErrnoError(2);
|
|
2724
|
-
}
|
|
2725
|
-
if ((stream.flags & 2097155) === 1) {
|
|
2726
|
-
throw new FS.ErrnoError(2);
|
|
2727
|
-
}
|
|
2728
|
-
if (!stream.stream_ops.mmap) {
|
|
2729
|
-
throw new FS.ErrnoError(43);
|
|
2730
|
-
}
|
|
2731
|
-
if (!length) {
|
|
2732
|
-
throw new FS.ErrnoError(28);
|
|
2733
|
-
}
|
|
2734
|
-
return stream.stream_ops.mmap(stream, length, position, prot, flags);
|
|
2735
|
-
},
|
|
2736
|
-
msync(stream, buffer, offset, length, mmapFlags) {
|
|
2737
|
-
if (!stream.stream_ops.msync) {
|
|
2738
|
-
return 0;
|
|
2739
|
-
}
|
|
2740
|
-
return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
|
|
2741
|
-
},
|
|
2742
|
-
ioctl(stream, cmd, arg) {
|
|
2743
|
-
if (!stream.stream_ops.ioctl) {
|
|
2744
|
-
throw new FS.ErrnoError(59);
|
|
2745
|
-
}
|
|
2746
|
-
return stream.stream_ops.ioctl(stream, cmd, arg);
|
|
2747
|
-
},
|
|
2748
|
-
readFile(path, opts = {}) {
|
|
2749
|
-
opts.flags = opts.flags || 0;
|
|
2750
|
-
opts.encoding = opts.encoding || "binary";
|
|
2751
|
-
if (opts.encoding !== "utf8" && opts.encoding !== "binary") {
|
|
2752
|
-
throw new Error(`Invalid encoding type "${opts.encoding}"`);
|
|
2753
|
-
}
|
|
2754
|
-
var ret;
|
|
2755
|
-
var stream = FS.open(path, opts.flags);
|
|
2756
|
-
var stat = FS.stat(path);
|
|
2757
|
-
var length = stat.size;
|
|
2758
|
-
var buf = new Uint8Array(length);
|
|
2759
|
-
FS.read(stream, buf, 0, length, 0);
|
|
2760
|
-
if (opts.encoding === "utf8") {
|
|
2761
|
-
ret = UTF8ArrayToString(buf);
|
|
2762
|
-
} else if (opts.encoding === "binary") {
|
|
2763
|
-
ret = buf;
|
|
2764
|
-
}
|
|
2765
|
-
FS.close(stream);
|
|
2766
|
-
return ret;
|
|
2767
|
-
},
|
|
2768
|
-
writeFile(path, data, opts = {}) {
|
|
2769
|
-
opts.flags = opts.flags || 577;
|
|
2770
|
-
var stream = FS.open(path, opts.flags, opts.mode);
|
|
2771
|
-
if (typeof data == "string") {
|
|
2772
|
-
var buf = new Uint8Array(lengthBytesUTF8(data) + 1);
|
|
2773
|
-
var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
|
|
2774
|
-
FS.write(stream, buf, 0, actualNumBytes, undefined, opts.canOwn);
|
|
2775
|
-
} else if (ArrayBuffer.isView(data)) {
|
|
2776
|
-
FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
|
|
2777
|
-
} else {
|
|
2778
|
-
throw new Error("Unsupported data type");
|
|
2779
|
-
}
|
|
2780
|
-
FS.close(stream);
|
|
2781
|
-
},
|
|
2782
|
-
cwd: () => FS.currentPath,
|
|
2783
|
-
chdir(path) {
|
|
2784
|
-
var lookup = FS.lookupPath(path, {
|
|
2785
|
-
follow: true
|
|
2786
|
-
});
|
|
2787
|
-
if (lookup.node === null) {
|
|
2788
|
-
throw new FS.ErrnoError(44);
|
|
2789
|
-
}
|
|
2790
|
-
if (!FS.isDir(lookup.node.mode)) {
|
|
2791
|
-
throw new FS.ErrnoError(54);
|
|
2792
|
-
}
|
|
2793
|
-
var errCode = FS.nodePermissions(lookup.node, "x");
|
|
2794
|
-
if (errCode) {
|
|
2795
|
-
throw new FS.ErrnoError(errCode);
|
|
2796
|
-
}
|
|
2797
|
-
FS.currentPath = lookup.path;
|
|
2798
|
-
},
|
|
2799
|
-
createDefaultDirectories() {
|
|
2800
|
-
FS.mkdir("/tmp");
|
|
2801
|
-
FS.mkdir("/home");
|
|
2802
|
-
FS.mkdir("/home/web_user");
|
|
2803
|
-
},
|
|
2804
|
-
createDefaultDevices() {
|
|
2805
|
-
// create /dev
|
|
2806
|
-
FS.mkdir("/dev");
|
|
2807
|
-
// setup /dev/null
|
|
2808
|
-
FS.registerDevice(FS.makedev(1, 3), {
|
|
2809
|
-
read: () => 0,
|
|
2810
|
-
write: (stream, buffer, offset, length, pos) => length,
|
|
2811
|
-
llseek: () => 0
|
|
2812
|
-
});
|
|
2813
|
-
FS.mkdev("/dev/null", FS.makedev(1, 3));
|
|
2814
|
-
// setup /dev/tty and /dev/tty1
|
|
2815
|
-
// stderr needs to print output using err() rather than out()
|
|
2816
|
-
// so we register a second tty just for it.
|
|
2817
|
-
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
|
|
2818
|
-
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
|
|
2819
|
-
FS.mkdev("/dev/tty", FS.makedev(5, 0));
|
|
2820
|
-
FS.mkdev("/dev/tty1", FS.makedev(6, 0));
|
|
2821
|
-
// setup /dev/[u]random
|
|
2822
|
-
// use a buffer to avoid overhead of individual crypto calls per byte
|
|
2823
|
-
var randomBuffer = new Uint8Array(1024), randomLeft = 0;
|
|
2824
|
-
var randomByte = () => {
|
|
2825
|
-
if (randomLeft === 0) {
|
|
2826
|
-
randomFill(randomBuffer);
|
|
2827
|
-
randomLeft = randomBuffer.byteLength;
|
|
2828
|
-
}
|
|
2829
|
-
return randomBuffer[--randomLeft];
|
|
2830
|
-
};
|
|
2831
|
-
FS.createDevice("/dev", "random", randomByte);
|
|
2832
|
-
FS.createDevice("/dev", "urandom", randomByte);
|
|
2833
|
-
// we're not going to emulate the actual shm device,
|
|
2834
|
-
// just create the tmp dirs that reside in it commonly
|
|
2835
|
-
FS.mkdir("/dev/shm");
|
|
2836
|
-
FS.mkdir("/dev/shm/tmp");
|
|
2837
|
-
},
|
|
2838
|
-
createSpecialDirectories() {
|
|
2839
|
-
// create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the
|
|
2840
|
-
// name of the stream for fd 6 (see test_unistd_ttyname)
|
|
2841
|
-
FS.mkdir("/proc");
|
|
2842
|
-
var proc_self = FS.mkdir("/proc/self");
|
|
2843
|
-
FS.mkdir("/proc/self/fd");
|
|
2844
|
-
FS.mount({
|
|
2845
|
-
mount() {
|
|
2846
|
-
var node = FS.createNode(proc_self, "fd", 16895, 73);
|
|
2847
|
-
node.stream_ops = {
|
|
2848
|
-
llseek: MEMFS.stream_ops.llseek
|
|
2849
|
-
};
|
|
2850
|
-
node.node_ops = {
|
|
2851
|
-
lookup(parent, name) {
|
|
2852
|
-
var fd = +name;
|
|
2853
|
-
var stream = FS.getStreamChecked(fd);
|
|
2854
|
-
var ret = {
|
|
2855
|
-
parent: null,
|
|
2856
|
-
mount: {
|
|
2857
|
-
mountpoint: "fake"
|
|
2858
|
-
},
|
|
2859
|
-
node_ops: {
|
|
2860
|
-
readlink: () => stream.path
|
|
2861
|
-
},
|
|
2862
|
-
id: fd + 1
|
|
2863
|
-
};
|
|
2864
|
-
ret.parent = ret;
|
|
2865
|
-
// make it look like a simple root node
|
|
2866
|
-
return ret;
|
|
2867
|
-
},
|
|
2868
|
-
readdir() {
|
|
2869
|
-
return Array.from(FS.streams.entries()).filter(([k, v]) => v).map(([k, v]) => k.toString());
|
|
2870
|
-
}
|
|
2871
|
-
};
|
|
2872
|
-
return node;
|
|
2873
|
-
}
|
|
2874
|
-
}, {}, "/proc/self/fd");
|
|
2875
|
-
},
|
|
2876
|
-
createStandardStreams(input, output, error) {
|
|
2877
|
-
// TODO deprecate the old functionality of a single
|
|
2878
|
-
// input / output callback and that utilizes FS.createDevice
|
|
2879
|
-
// and instead require a unique set of stream ops
|
|
2880
|
-
// by default, we symlink the standard streams to the
|
|
2881
|
-
// default tty devices. however, if the standard streams
|
|
2882
|
-
// have been overwritten we create a unique device for
|
|
2883
|
-
// them instead.
|
|
2884
|
-
if (input) {
|
|
2885
|
-
FS.createDevice("/dev", "stdin", input);
|
|
2886
|
-
} else {
|
|
2887
|
-
FS.symlink("/dev/tty", "/dev/stdin");
|
|
2888
|
-
}
|
|
2889
|
-
if (output) {
|
|
2890
|
-
FS.createDevice("/dev", "stdout", null, output);
|
|
2891
|
-
} else {
|
|
2892
|
-
FS.symlink("/dev/tty", "/dev/stdout");
|
|
2893
|
-
}
|
|
2894
|
-
if (error) {
|
|
2895
|
-
FS.createDevice("/dev", "stderr", null, error);
|
|
2896
|
-
} else {
|
|
2897
|
-
FS.symlink("/dev/tty1", "/dev/stderr");
|
|
2898
|
-
}
|
|
2899
|
-
// open default streams for the stdin, stdout and stderr devices
|
|
2900
|
-
var stdin = FS.open("/dev/stdin", 0);
|
|
2901
|
-
var stdout = FS.open("/dev/stdout", 1);
|
|
2902
|
-
var stderr = FS.open("/dev/stderr", 1);
|
|
2903
|
-
},
|
|
2904
|
-
staticInit() {
|
|
2905
|
-
FS.nameTable = new Array(4096);
|
|
2906
|
-
FS.mount(MEMFS, {}, "/");
|
|
2907
|
-
FS.createDefaultDirectories();
|
|
2908
|
-
FS.createDefaultDevices();
|
|
2909
|
-
FS.createSpecialDirectories();
|
|
2910
|
-
FS.filesystems = {
|
|
2911
|
-
"MEMFS": MEMFS,
|
|
2912
|
-
"PROXYFS": PROXYFS
|
|
2913
|
-
};
|
|
2914
|
-
},
|
|
2915
|
-
init(input, output, error) {
|
|
2916
|
-
FS.initialized = true;
|
|
2917
|
-
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
|
|
2918
|
-
input ??= Module["stdin"];
|
|
2919
|
-
output ??= Module["stdout"];
|
|
2920
|
-
error ??= Module["stderr"];
|
|
2921
|
-
FS.createStandardStreams(input, output, error);
|
|
2922
|
-
},
|
|
2923
|
-
quit() {
|
|
2924
|
-
FS.initialized = false;
|
|
2925
|
-
// force-flush all streams, so we get musl std streams printed out
|
|
2926
|
-
// close all of our streams
|
|
2927
|
-
for (var stream of FS.streams) {
|
|
2928
|
-
if (stream) {
|
|
2929
|
-
FS.close(stream);
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
},
|
|
2933
|
-
findObject(path, dontResolveLastLink) {
|
|
2934
|
-
var ret = FS.analyzePath(path, dontResolveLastLink);
|
|
2935
|
-
if (!ret.exists) {
|
|
2936
|
-
return null;
|
|
2937
|
-
}
|
|
2938
|
-
return ret.object;
|
|
2939
|
-
},
|
|
2940
|
-
analyzePath(path, dontResolveLastLink) {
|
|
2941
|
-
// operate from within the context of the symlink's target
|
|
2942
|
-
try {
|
|
2943
|
-
var lookup = FS.lookupPath(path, {
|
|
2944
|
-
follow: !dontResolveLastLink
|
|
2945
|
-
});
|
|
2946
|
-
path = lookup.path;
|
|
2947
|
-
} catch (e) {}
|
|
2948
|
-
var ret = {
|
|
2949
|
-
isRoot: false,
|
|
2950
|
-
exists: false,
|
|
2951
|
-
error: 0,
|
|
2952
|
-
name: null,
|
|
2953
|
-
path: null,
|
|
2954
|
-
object: null,
|
|
2955
|
-
parentExists: false,
|
|
2956
|
-
parentPath: null,
|
|
2957
|
-
parentObject: null
|
|
2958
|
-
};
|
|
2959
|
-
try {
|
|
2960
|
-
var lookup = FS.lookupPath(path, {
|
|
2961
|
-
parent: true
|
|
2962
|
-
});
|
|
2963
|
-
ret.parentExists = true;
|
|
2964
|
-
ret.parentPath = lookup.path;
|
|
2965
|
-
ret.parentObject = lookup.node;
|
|
2966
|
-
ret.name = PATH.basename(path);
|
|
2967
|
-
lookup = FS.lookupPath(path, {
|
|
2968
|
-
follow: !dontResolveLastLink
|
|
2969
|
-
});
|
|
2970
|
-
ret.exists = true;
|
|
2971
|
-
ret.path = lookup.path;
|
|
2972
|
-
ret.object = lookup.node;
|
|
2973
|
-
ret.name = lookup.node.name;
|
|
2974
|
-
ret.isRoot = lookup.path === "/";
|
|
2975
|
-
} catch (e) {
|
|
2976
|
-
ret.error = e.errno;
|
|
2977
|
-
}
|
|
2978
|
-
return ret;
|
|
2979
|
-
},
|
|
2980
|
-
createPath(parent, path, canRead, canWrite) {
|
|
2981
|
-
parent = typeof parent == "string" ? parent : FS.getPath(parent);
|
|
2982
|
-
var parts = path.split("/").reverse();
|
|
2983
|
-
while (parts.length) {
|
|
2984
|
-
var part = parts.pop();
|
|
2985
|
-
if (!part) continue;
|
|
2986
|
-
var current = PATH.join2(parent, part);
|
|
2987
|
-
try {
|
|
2988
|
-
FS.mkdir(current);
|
|
2989
|
-
} catch (e) {
|
|
2990
|
-
if (e.errno != 20) throw e;
|
|
2991
|
-
}
|
|
2992
|
-
parent = current;
|
|
2993
|
-
}
|
|
2994
|
-
return current;
|
|
2995
|
-
},
|
|
2996
|
-
createFile(parent, name, properties, canRead, canWrite) {
|
|
2997
|
-
var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
|
|
2998
|
-
var mode = FS_getMode(canRead, canWrite);
|
|
2999
|
-
return FS.create(path, mode);
|
|
3000
|
-
},
|
|
3001
|
-
createDataFile(parent, name, data, canRead, canWrite, canOwn) {
|
|
3002
|
-
var path = name;
|
|
3003
|
-
if (parent) {
|
|
3004
|
-
parent = typeof parent == "string" ? parent : FS.getPath(parent);
|
|
3005
|
-
path = name ? PATH.join2(parent, name) : parent;
|
|
3006
|
-
}
|
|
3007
|
-
var mode = FS_getMode(canRead, canWrite);
|
|
3008
|
-
var node = FS.create(path, mode);
|
|
3009
|
-
if (data) {
|
|
3010
|
-
if (typeof data == "string") {
|
|
3011
|
-
var arr = new Array(data.length);
|
|
3012
|
-
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
|
3013
|
-
data = arr;
|
|
3014
|
-
}
|
|
3015
|
-
// make sure we can write to the file
|
|
3016
|
-
FS.chmod(node, mode | 146);
|
|
3017
|
-
var stream = FS.open(node, 577);
|
|
3018
|
-
FS.write(stream, data, 0, data.length, 0, canOwn);
|
|
3019
|
-
FS.close(stream);
|
|
3020
|
-
FS.chmod(node, mode);
|
|
3021
|
-
}
|
|
3022
|
-
},
|
|
3023
|
-
createDevice(parent, name, input, output) {
|
|
3024
|
-
var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
|
|
3025
|
-
var mode = FS_getMode(!!input, !!output);
|
|
3026
|
-
FS.createDevice.major ??= 64;
|
|
3027
|
-
var dev = FS.makedev(FS.createDevice.major++, 0);
|
|
3028
|
-
// Create a fake device that a set of stream ops to emulate
|
|
3029
|
-
// the old behavior.
|
|
3030
|
-
FS.registerDevice(dev, {
|
|
3031
|
-
open(stream) {
|
|
3032
|
-
stream.seekable = false;
|
|
3033
|
-
},
|
|
3034
|
-
close(stream) {
|
|
3035
|
-
// flush any pending line data
|
|
3036
|
-
if (output?.buffer?.length) {
|
|
3037
|
-
output(10);
|
|
3038
|
-
}
|
|
3039
|
-
},
|
|
3040
|
-
read(stream, buffer, offset, length, pos) {
|
|
3041
|
-
var bytesRead = 0;
|
|
3042
|
-
for (var i = 0; i < length; i++) {
|
|
3043
|
-
var result;
|
|
3044
|
-
try {
|
|
3045
|
-
result = input();
|
|
3046
|
-
} catch (e) {
|
|
3047
|
-
throw new FS.ErrnoError(29);
|
|
3048
|
-
}
|
|
3049
|
-
if (result === undefined && bytesRead === 0) {
|
|
3050
|
-
throw new FS.ErrnoError(6);
|
|
3051
|
-
}
|
|
3052
|
-
if (result === null || result === undefined) break;
|
|
3053
|
-
bytesRead++;
|
|
3054
|
-
buffer[offset + i] = result;
|
|
3055
|
-
}
|
|
3056
|
-
if (bytesRead) {
|
|
3057
|
-
stream.node.atime = Date.now();
|
|
3058
|
-
}
|
|
3059
|
-
return bytesRead;
|
|
3060
|
-
},
|
|
3061
|
-
write(stream, buffer, offset, length, pos) {
|
|
3062
|
-
for (var i = 0; i < length; i++) {
|
|
3063
|
-
try {
|
|
3064
|
-
output(buffer[offset + i]);
|
|
3065
|
-
} catch (e) {
|
|
3066
|
-
throw new FS.ErrnoError(29);
|
|
3067
|
-
}
|
|
3068
|
-
}
|
|
3069
|
-
if (length) {
|
|
3070
|
-
stream.node.mtime = stream.node.ctime = Date.now();
|
|
3071
|
-
}
|
|
3072
|
-
return i;
|
|
3073
|
-
}
|
|
3074
|
-
});
|
|
3075
|
-
return FS.mkdev(path, mode, dev);
|
|
3076
|
-
},
|
|
3077
|
-
forceLoadFile(obj) {
|
|
3078
|
-
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
|
|
3079
|
-
if (typeof XMLHttpRequest != "undefined") {
|
|
3080
|
-
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.");
|
|
3081
|
-
} else {
|
|
3082
|
-
// Command-line.
|
|
3083
|
-
try {
|
|
3084
|
-
obj.contents = readBinary(obj.url);
|
|
3085
|
-
obj.usedBytes = obj.contents.length;
|
|
3086
|
-
} catch (e) {
|
|
3087
|
-
throw new FS.ErrnoError(29);
|
|
3088
|
-
}
|
|
3089
|
-
}
|
|
3090
|
-
},
|
|
3091
|
-
createLazyFile(parent, name, url, canRead, canWrite) {
|
|
3092
|
-
// Lazy chunked Uint8Array (implements get and length from Uint8Array).
|
|
3093
|
-
// Actual getting is abstracted away for eventual reuse.
|
|
3094
|
-
class LazyUint8Array {
|
|
3095
|
-
lengthKnown=false;
|
|
3096
|
-
chunks=[];
|
|
3097
|
-
// Loaded chunks. Index is the chunk number
|
|
3098
|
-
get(idx) {
|
|
3099
|
-
if (idx > this.length - 1 || idx < 0) {
|
|
3100
|
-
return undefined;
|
|
3101
|
-
}
|
|
3102
|
-
var chunkOffset = idx % this.chunkSize;
|
|
3103
|
-
var chunkNum = (idx / this.chunkSize) | 0;
|
|
3104
|
-
return this.getter(chunkNum)[chunkOffset];
|
|
3105
|
-
}
|
|
3106
|
-
setDataGetter(getter) {
|
|
3107
|
-
this.getter = getter;
|
|
3108
|
-
}
|
|
3109
|
-
cacheLength() {
|
|
3110
|
-
// Find length
|
|
3111
|
-
var xhr = new XMLHttpRequest;
|
|
3112
|
-
xhr.open("HEAD", url, false);
|
|
3113
|
-
xhr.send(null);
|
|
3114
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3115
|
-
var datalength = Number(xhr.getResponseHeader("Content-length"));
|
|
3116
|
-
var header;
|
|
3117
|
-
var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
|
|
3118
|
-
var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
|
|
3119
|
-
var chunkSize = 1024 * 1024;
|
|
3120
|
-
// Chunk size in bytes
|
|
3121
|
-
if (!hasByteServing) chunkSize = datalength;
|
|
3122
|
-
// Function to get a range from the remote URL.
|
|
3123
|
-
var doXHR = (from, to) => {
|
|
3124
|
-
if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
|
|
3125
|
-
if (to > datalength - 1) throw new Error("only " + datalength + " bytes available! programmer error!");
|
|
3126
|
-
// TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
|
|
3127
|
-
var xhr = new XMLHttpRequest;
|
|
3128
|
-
xhr.open("GET", url, false);
|
|
3129
|
-
if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
|
|
3130
|
-
// Some hints to the browser that we want binary data.
|
|
3131
|
-
xhr.responseType = "arraybuffer";
|
|
3132
|
-
if (xhr.overrideMimeType) {
|
|
3133
|
-
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
3134
|
-
}
|
|
3135
|
-
xhr.send(null);
|
|
3136
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3137
|
-
if (xhr.response !== undefined) {
|
|
3138
|
-
return new Uint8Array(/** @type{Array<number>} */ (xhr.response || []));
|
|
3139
|
-
}
|
|
3140
|
-
return intArrayFromString(xhr.responseText || "", true);
|
|
3141
|
-
};
|
|
3142
|
-
var lazyArray = this;
|
|
3143
|
-
lazyArray.setDataGetter(chunkNum => {
|
|
3144
|
-
var start = chunkNum * chunkSize;
|
|
3145
|
-
var end = (chunkNum + 1) * chunkSize - 1;
|
|
3146
|
-
// including this byte
|
|
3147
|
-
end = Math.min(end, datalength - 1);
|
|
3148
|
-
// if datalength-1 is selected, this is the last block
|
|
3149
|
-
if (typeof lazyArray.chunks[chunkNum] == "undefined") {
|
|
3150
|
-
lazyArray.chunks[chunkNum] = doXHR(start, end);
|
|
3151
|
-
}
|
|
3152
|
-
if (typeof lazyArray.chunks[chunkNum] == "undefined") throw new Error("doXHR failed!");
|
|
3153
|
-
return lazyArray.chunks[chunkNum];
|
|
3154
|
-
});
|
|
3155
|
-
if (usesGzip || !datalength) {
|
|
3156
|
-
// if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
|
|
3157
|
-
chunkSize = datalength = 1;
|
|
3158
|
-
// this will force getter(0)/doXHR do download the whole file
|
|
3159
|
-
datalength = this.getter(0).length;
|
|
3160
|
-
chunkSize = datalength;
|
|
3161
|
-
out("LazyFiles on gzip forces download of the whole file when length is accessed");
|
|
3162
|
-
}
|
|
3163
|
-
this._length = datalength;
|
|
3164
|
-
this._chunkSize = chunkSize;
|
|
3165
|
-
this.lengthKnown = true;
|
|
3166
|
-
}
|
|
3167
|
-
get length() {
|
|
3168
|
-
if (!this.lengthKnown) {
|
|
3169
|
-
this.cacheLength();
|
|
3170
|
-
}
|
|
3171
|
-
return this._length;
|
|
3172
|
-
}
|
|
3173
|
-
get chunkSize() {
|
|
3174
|
-
if (!this.lengthKnown) {
|
|
3175
|
-
this.cacheLength();
|
|
3176
|
-
}
|
|
3177
|
-
return this._chunkSize;
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
if (typeof XMLHttpRequest != "undefined") {
|
|
3181
|
-
if (!ENVIRONMENT_IS_WORKER) throw "Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";
|
|
3182
|
-
var lazyArray = new LazyUint8Array;
|
|
3183
|
-
var properties = {
|
|
3184
|
-
isDevice: false,
|
|
3185
|
-
contents: lazyArray
|
|
3186
|
-
};
|
|
3187
|
-
} else {
|
|
3188
|
-
var properties = {
|
|
3189
|
-
isDevice: false,
|
|
3190
|
-
url
|
|
3191
|
-
};
|
|
3192
|
-
}
|
|
3193
|
-
var node = FS.createFile(parent, name, properties, canRead, canWrite);
|
|
3194
|
-
// This is a total hack, but I want to get this lazy file code out of the
|
|
3195
|
-
// core of MEMFS. If we want to keep this lazy file concept I feel it should
|
|
3196
|
-
// be its own thin LAZYFS proxying calls to MEMFS.
|
|
3197
|
-
if (properties.contents) {
|
|
3198
|
-
node.contents = properties.contents;
|
|
3199
|
-
} else if (properties.url) {
|
|
3200
|
-
node.contents = null;
|
|
3201
|
-
node.url = properties.url;
|
|
3202
|
-
}
|
|
3203
|
-
// Add a function that defers querying the file size until it is asked the first time.
|
|
3204
|
-
Object.defineProperties(node, {
|
|
3205
|
-
usedBytes: {
|
|
3206
|
-
get: function() {
|
|
3207
|
-
return this.contents.length;
|
|
3208
|
-
}
|
|
3209
|
-
}
|
|
3210
|
-
});
|
|
3211
|
-
// override each stream op with one that tries to force load the lazy file first
|
|
3212
|
-
var stream_ops = {};
|
|
3213
|
-
var keys = Object.keys(node.stream_ops);
|
|
3214
|
-
keys.forEach(key => {
|
|
3215
|
-
var fn = node.stream_ops[key];
|
|
3216
|
-
stream_ops[key] = (...args) => {
|
|
3217
|
-
FS.forceLoadFile(node);
|
|
3218
|
-
return fn(...args);
|
|
3219
|
-
};
|
|
3220
|
-
});
|
|
3221
|
-
function writeChunks(stream, buffer, offset, length, position) {
|
|
3222
|
-
var contents = stream.node.contents;
|
|
3223
|
-
if (position >= contents.length) return 0;
|
|
3224
|
-
var size = Math.min(contents.length - position, length);
|
|
3225
|
-
if (contents.slice) {
|
|
3226
|
-
// normal array
|
|
3227
|
-
for (var i = 0; i < size; i++) {
|
|
3228
|
-
buffer[offset + i] = contents[position + i];
|
|
3229
|
-
}
|
|
3230
|
-
} else {
|
|
3231
|
-
for (var i = 0; i < size; i++) {
|
|
3232
|
-
// LazyUint8Array from sync binary XHR
|
|
3233
|
-
buffer[offset + i] = contents.get(position + i);
|
|
3234
|
-
}
|
|
3235
|
-
}
|
|
3236
|
-
return size;
|
|
3237
|
-
}
|
|
3238
|
-
// use a custom read function
|
|
3239
|
-
stream_ops.read = (stream, buffer, offset, length, position) => {
|
|
3240
|
-
FS.forceLoadFile(node);
|
|
3241
|
-
return writeChunks(stream, buffer, offset, length, position);
|
|
3242
|
-
};
|
|
3243
|
-
// use a custom mmap function
|
|
3244
|
-
stream_ops.mmap = (stream, length, position, prot, flags) => {
|
|
3245
|
-
FS.forceLoadFile(node);
|
|
3246
|
-
var ptr = mmapAlloc(length);
|
|
3247
|
-
if (!ptr) {
|
|
3248
|
-
throw new FS.ErrnoError(48);
|
|
3249
|
-
}
|
|
3250
|
-
writeChunks(stream, HEAP8, ptr, length, position);
|
|
3251
|
-
return {
|
|
3252
|
-
ptr,
|
|
3253
|
-
allocated: true
|
|
3254
|
-
};
|
|
3255
|
-
};
|
|
3256
|
-
node.stream_ops = stream_ops;
|
|
3257
|
-
return node;
|
|
3258
|
-
}
|
|
3259
|
-
};
|
|
3260
|
-
|
|
3261
|
-
var FS_createPath = (...args) => FS.createPath(...args);
|
|
3262
|
-
|
|
3263
|
-
var FS_unlink = (...args) => FS.unlink(...args);
|
|
3264
|
-
|
|
3265
|
-
var FS_createLazyFile = (...args) => FS.createLazyFile(...args);
|
|
3266
|
-
|
|
3267
|
-
var FS_createDevice = (...args) => FS.createDevice(...args);
|
|
3268
|
-
|
|
3269
|
-
FS.createPreloadedFile = FS_createPreloadedFile;
|
|
3270
|
-
|
|
3271
|
-
FS.staticInit();
|
|
3272
|
-
|
|
3273
|
-
// This error may happen quite a bit. To avoid overhead we reuse it (and
|
|
3274
|
-
// suffer a lack of stack info).
|
|
3275
|
-
MEMFS.doesNotExistError = new FS.ErrnoError(44);
|
|
3276
|
-
|
|
3277
|
-
/** @suppress {checkTypes} */ MEMFS.doesNotExistError.stack = "<generic error, no stack>";
|
|
3278
|
-
|
|
3279
|
-
// End JS library code
|
|
3280
|
-
// include: postlibrary.js
|
|
3281
|
-
// This file is included after the automatically-generated JS library code
|
|
3282
|
-
// but before the wasm module is created.
|
|
3283
|
-
{
|
|
3284
|
-
// Begin ATMODULES hooks
|
|
3285
|
-
if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
|
|
3286
|
-
if (Module["preloadPlugins"]) preloadPlugins = Module["preloadPlugins"];
|
|
3287
|
-
if (Module["print"]) out = Module["print"];
|
|
3288
|
-
if (Module["printErr"]) err = Module["printErr"];
|
|
3289
|
-
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
|
|
3290
|
-
// End ATMODULES hooks
|
|
3291
|
-
if (Module["arguments"]) arguments_ = Module["arguments"];
|
|
3292
|
-
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
|
|
3293
|
-
}
|
|
3294
|
-
|
|
3295
|
-
// Begin runtime exports
|
|
3296
|
-
Module["addRunDependency"] = addRunDependency;
|
|
3297
|
-
|
|
3298
|
-
Module["removeRunDependency"] = removeRunDependency;
|
|
3299
|
-
|
|
3300
|
-
Module["ERRNO_CODES"] = ERRNO_CODES;
|
|
3301
|
-
|
|
3302
|
-
Module["PATH"] = PATH;
|
|
3303
|
-
|
|
3304
|
-
Module["FS_createPreloadedFile"] = FS_createPreloadedFile;
|
|
3305
|
-
|
|
3306
|
-
Module["FS_unlink"] = FS_unlink;
|
|
3307
|
-
|
|
3308
|
-
Module["FS_createPath"] = FS_createPath;
|
|
3309
|
-
|
|
3310
|
-
Module["FS_createDevice"] = FS_createDevice;
|
|
3311
|
-
|
|
3312
|
-
Module["FS"] = FS;
|
|
3313
|
-
|
|
3314
|
-
Module["FS_createDataFile"] = FS_createDataFile;
|
|
3315
|
-
|
|
3316
|
-
Module["FS_createLazyFile"] = FS_createLazyFile;
|
|
3317
|
-
|
|
3318
|
-
Module["PROXYFS"] = PROXYFS;
|
|
3319
|
-
|
|
3320
|
-
// End runtime exports
|
|
3321
|
-
// Begin JS library exports
|
|
3322
|
-
// End JS library exports
|
|
3323
|
-
// end include: postlibrary.js
|
|
3324
|
-
var wasmImports = {};
|
|
3325
|
-
|
|
3326
|
-
var wasmExports = await createWasm();
|
|
3327
|
-
|
|
3328
|
-
// Imports from the Wasm binary.
|
|
3329
|
-
var ___wasm_call_ctors = wasmExports["__wasm_call_ctors"];
|
|
3330
|
-
|
|
3331
|
-
var ___trap = wasmExports["__trap"];
|
|
3332
|
-
|
|
3333
|
-
var __emscripten_stack_alloc = wasmExports["_emscripten_stack_alloc"];
|
|
3334
|
-
|
|
3335
|
-
// include: postamble.js
|
|
3336
|
-
// === Auto-generated postamble setup entry stuff ===
|
|
3337
|
-
function run() {
|
|
3338
|
-
if (runDependencies > 0) {
|
|
3339
|
-
dependenciesFulfilled = run;
|
|
3340
|
-
return;
|
|
3341
|
-
}
|
|
3342
|
-
preRun();
|
|
3343
|
-
// a preRun added a dependency, run will be called later
|
|
3344
|
-
if (runDependencies > 0) {
|
|
3345
|
-
dependenciesFulfilled = run;
|
|
3346
|
-
return;
|
|
3347
|
-
}
|
|
3348
|
-
function doRun() {
|
|
3349
|
-
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
3350
|
-
// or while the async setStatus time below was happening
|
|
3351
|
-
Module["calledRun"] = true;
|
|
3352
|
-
if (ABORT) return;
|
|
3353
|
-
initRuntime();
|
|
3354
|
-
readyPromiseResolve(Module);
|
|
3355
|
-
Module["onRuntimeInitialized"]?.();
|
|
3356
|
-
postRun();
|
|
3357
|
-
}
|
|
3358
|
-
if (Module["setStatus"]) {
|
|
3359
|
-
Module["setStatus"]("Running...");
|
|
3360
|
-
setTimeout(() => {
|
|
3361
|
-
setTimeout(() => Module["setStatus"](""), 1);
|
|
3362
|
-
doRun();
|
|
3363
|
-
}, 1);
|
|
3364
|
-
} else {
|
|
3365
|
-
doRun();
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
|
|
3369
|
-
function preInit() {
|
|
3370
|
-
if (Module["preInit"]) {
|
|
3371
|
-
if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
|
|
3372
|
-
while (Module["preInit"].length > 0) {
|
|
3373
|
-
Module["preInit"].shift()();
|
|
3374
|
-
}
|
|
3375
|
-
}
|
|
3376
|
-
}
|
|
3377
|
-
|
|
3378
|
-
preInit();
|
|
3379
|
-
|
|
3380
|
-
run();
|
|
3381
|
-
|
|
3382
|
-
// end include: postamble.js
|
|
3383
|
-
// include: postamble_modularize.js
|
|
3384
|
-
// In MODULARIZE mode we wrap the generated code in a factory function
|
|
3385
|
-
// and return either the Module itself, or a promise of the module.
|
|
3386
|
-
// We assign to the `moduleRtn` global here and configure closure to see
|
|
3387
|
-
// this as and extern so it won't get minified.
|
|
3388
|
-
moduleRtn = readyPromise;
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
return moduleRtn;
|
|
3392
|
-
}
|
|
3393
|
-
);
|
|
3394
|
-
})();
|
|
3395
|
-
if (typeof exports === 'object' && typeof module === 'object') {
|
|
3396
|
-
module.exports = Module;
|
|
3397
|
-
// This default export looks redundant, but it allows TS to import this
|
|
3398
|
-
// commonjs style module.
|
|
3399
|
-
module.exports.default = Module;
|
|
3400
|
-
} else if (typeof define === 'function' && define['amd'])
|
|
3401
|
-
define([], () => Module);
|