blob: 46a736659bae479fea8699d5ea9c9f4df31ff881 [file] [log] [blame]
/**
* @license
* Copyright 2019 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
readBinary = (filename) => {
// We need to re-wrap `file://` strings to URLs. Normalizing isn't
// necessary in that case, the path should already be absolute.
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
var ret = fs.readFileSync(filename);
#if ASSERTIONS
assert(ret.buffer);
#endif
return ret;
};
readAsync = (filename, binary = true) => {
// See the comment in the `readBinary` function.
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
return new Promise((resolve, reject) => {
fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
if (err) reject(err);
else resolve(binary ? data.buffer : data);
});
});
};