forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_shell_read.js
More file actions
43 lines (40 loc) · 1.05 KB
/
node_shell_read.js
File metadata and controls
43 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @license
* Copyright 2019 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
read_ = function shell_read(filename, binary) {
#if SUPPORT_BASE64_EMBEDDING
var ret = tryParseAsDataURI(filename);
if (ret) {
return binary ? ret : ret.toString();
}
#endif
if (!nodeFS) nodeFS = require('fs');
if (!nodePath) nodePath = require('path');
filename = nodePath['normalize'](filename);
return nodeFS['readFileSync'](filename, binary ? null : 'utf8');
};
readBinary = function readBinary(filename) {
var ret = read_(filename, true);
if (!ret.buffer) {
ret = new Uint8Array(ret);
}
assert(ret.buffer);
return ret;
};
readAsync = function readAsync(filename, onload, onerror) {
#if SUPPORT_BASE64_EMBEDDING
var ret = tryParseAsDataURI(filename);
if (ret) {
onload(ret);
}
#endif
if (!nodeFS) nodeFS = require('fs');
if (!nodePath) nodePath = require('path');
filename = nodePath['normalize'](filename);
nodeFS['readFile'](filename, function(err, data) {
if (err) onerror(err);
else onload(data.buffer);
});
};