forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_asmfs.js
51 lines (45 loc) · 1.52 KB
/
library_asmfs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @license
* Copyright 2020 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
var asmFS = {
$FS: {
populate: function(path, mode) {
var pathCString = allocate(intArrayFromString(path), ALLOC_NORMAL);
mode = (mode !== undefined) ? mode : 511 /* 0777 */;
_emscripten_asmfs_populate(pathCString, mode);
_free(pathCString);
},
mkdir: function(path, mode) {
mode = (mode !== undefined) ? mode : 511 /* 0777 */;
var pathCString = allocate(intArrayFromString(path), ALLOC_NORMAL);
_emscripten_asmfs_mkdir(pathCString, mode);
_free(pathCString);
},
mkdirTree: function(path, mode) {
var dirs = path.split('/');
var d = '';
for (var i = 0; i < dirs.length; ++i) {
if (!dirs[i]) continue;
d += '/' + dirs[i];
FS.mkdir(d, mode);
}
},
setRemoteUrl: function(path, remoteUrl) {
var pathCString = allocate(intArrayFromString(path), ALLOC_NORMAL);
var remoteUrlCString = allocate(intArrayFromString(remoteUrl), ALLOC_NORMAL);
_emscripten_asmfs_set_remote_url(pathCString, remoteUrlCString);
_free(pathCString);
_free(remoteUrlCString);
},
setFileData: function(path, data) {
var dataInHeap = _malloc(data.length);
HEAPU8.set(data, dataInHeap);
var pathCString = allocate(intArrayFromString(path), ALLOC_NORMAL);
_emscripten_asmfs_set_file_data(pathCString, dataInHeap, data.length);
_free(pathCString);
}
}
};
mergeInto(LibraryManager.library, asmFS);