support reading binary data in the shell/node

This commit is contained in:
Alon Zakai 2013-04-05 13:34:00 -07:00
Родитель 34adb13ead
Коммит f8c930551e
1 изменённых файлов: 10 добавлений и 9 удалений

Просмотреть файл

@ -24,17 +24,20 @@ if (ENVIRONMENT_IS_NODE) {
var nodeFS = require('fs');
var nodePath = require('path');
Module['read'] = function(filename) {
Module['read'] = function(filename, binary) {
filename = nodePath['normalize'](filename);
var ret = nodeFS['readFileSync'](filename).toString();
var ret = nodeFS['readFileSync'](filename);
// The path is absolute if the normalized version is the same as the resolved.
if (!ret && filename != nodePath['resolve'](filename)) {
filename = path.join(__dirname, '..', 'src', filename);
ret = nodeFS['readFileSync'](filename).toString();
ret = nodeFS['readFileSync'](filename);
}
if (ret && !binary) ret = ret.toString();
return ret;
};
Module['readBinary'] = function(filename) { return Module['read'](filename, true) };
Module['load'] = function(f) {
globalEval(read(f));
};
@ -48,12 +51,10 @@ if (ENVIRONMENT_IS_SHELL) {
Module['print'] = print;
if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
// Polyfill over SpiderMonkey/V8 differences
if (typeof read != 'undefined') {
Module['read'] = read;
} else {
Module['read'] = function(f) { snarf(f) };
}
Module['read'] = read;
Module['readBinary'] = function(f) {
return read(f, 'binary');
};
if (!Module['arguments']) {
if (typeof scriptArgs != 'undefined') {