Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/node_shell_read.js
4128 views
1
/**
2
* @license
3
* Copyright 2019 The Emscripten Authors
4
* SPDX-License-Identifier: MIT
5
*/
6
7
readBinary = (filename) => {
8
// We need to re-wrap `file://` strings to URLs.
9
filename = isFileURI(filename) ? new URL(filename) : filename;
10
var ret = fs.readFileSync(filename);
11
#if ASSERTIONS
12
assert(Buffer.isBuffer(ret));
13
#endif
14
return ret;
15
};
16
17
readAsync = async (filename, binary = true) => {
18
// See the comment in the `readBinary` function.
19
filename = isFileURI(filename) ? new URL(filename) : filename;
20
var ret = fs.readFileSync(filename, binary ? undefined : 'utf8');
21
#if ASSERTIONS
22
assert(binary ? Buffer.isBuffer(ret) : typeof ret == 'string');
23
#endif
24
return ret;
25
};
26
27