Skip to content

Commit b9734fe

Browse files
committed
Update SYSTEM .READ-FILE to read as text-mode or binary
1 parent c380147 commit b9734fe

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

lib.js

+35-24
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ var create = (globals) => {
748748
try {
749749
return [true, readString(x)];
750750
}
751-
catch (__e90) {
752-
return [false, __e90];
751+
catch (__e91) {
752+
return [false, __e91];
753753
}
754754
})();
755755
var __ok = ____id[0];
@@ -3504,8 +3504,19 @@ var create = (globals) => {
35043504
var childProcess = require("child_process");
35053505
var path = require("path");
35063506
var process = require("process");
3507-
var readFile = (path) => {
3508-
return fs.readFileSync(path, "utf8");
3507+
var readFile = (path, __x112) => {
3508+
var __e88;
3509+
if (is63(__x112)) {
3510+
__e88 = __x112;
3511+
} else {
3512+
__e88 = "text";
3513+
}
3514+
var __mode = __e88;
3515+
if (__mode === "text") {
3516+
return fs.readFileSync(path, "utf8").replace(/\r/g, "");
3517+
} else {
3518+
return fs.readFileSync(path);
3519+
}
35093520
};
35103521
var writeFile = (path, data) => {
35113522
return fs.writeFileSync(path, data, "utf8");
@@ -3570,8 +3581,8 @@ var create = (globals) => {
35703581
try {
35713582
return [true, compiler["eval"](form)];
35723583
}
3573-
catch (__e91) {
3574-
return [false, __e91];
3584+
catch (__e92) {
3585+
return [false, __e92];
35753586
}
35763587
})();
35773588
var __ok1 = ____id97[0];
@@ -3613,11 +3624,11 @@ var create = (globals) => {
36133624
return str(body);
36143625
} else {
36153626
var __s13 = "(";
3616-
var ____x112 = body;
3627+
var ____x113 = body;
36173628
var ____i59 = 0;
3618-
while (____i59 < _35(____x112)) {
3619-
var __x113 = ____x112[____i59];
3620-
__s13 = __s13 + str(__x113) + "\n\n";
3629+
while (____i59 < _35(____x113)) {
3630+
var __x114 = ____x113[____i59];
3631+
__s13 = __s13 + str(__x114) + "\n\n";
36213632
____i59 = ____i59 + 1;
36223633
}
36233634
return __s13 + ")";
@@ -3655,10 +3666,10 @@ var create = (globals) => {
36553666
var __code1 = compileFile(path);
36563667
var __prev = _G.exports || {};
36573668
_G.exports = {};
3658-
var __x114 = _G.exports;
3669+
var __x115 = _G.exports;
36593670
compiler.run(__code1);
36603671
_G.exports = __prev;
3661-
return __x114;
3672+
return __x115;
36623673
};
36633674
_G.load = load;
36643675
var scriptFile63 = (path) => {
@@ -3736,10 +3747,10 @@ var create = (globals) => {
37363747
}
37373748
__i60 = __i60 + 1;
37383749
}
3739-
var ____x115 = __pre1;
3750+
var ____x116 = __pre1;
37403751
var ____i61 = 0;
3741-
while (____i61 < _35(____x115)) {
3742-
var __file = ____x115[____i61];
3752+
while (____i61 < _35(____x116)) {
3753+
var __file = ____x116[____i61];
37433754
runFile(__file);
37443755
____i61 = ____i61 + 1;
37453756
}
@@ -3750,19 +3761,19 @@ var create = (globals) => {
37503761
return repl();
37513762
}
37523763
} else {
3753-
var __e88;
3764+
var __e89;
37543765
if (__op2 === "expand") {
3755-
__e88 = ppToString(expandFile(__input));
3766+
__e89 = ppToString(expandFile(__input));
37563767
} else {
3757-
var __e89;
3768+
var __e90;
37583769
if (__op2 === "read") {
3759-
__e89 = ppToString(readFile(__input));
3770+
__e90 = ppToString(readFile(__input));
37603771
} else {
3761-
__e89 = compileFile(__input);
3772+
__e90 = compileFile(__input);
37623773
}
3763-
__e88 = __e89;
3774+
__e89 = __e90;
37643775
}
3765-
var __code2 = __e88;
3776+
var __code2 = __e89;
37663777
if (nil63(__output) || __output === "-") {
37673778
return print(__code2);
37683779
} else {
@@ -3788,8 +3799,8 @@ var create = (globals) => {
37883799
Object.assign(_G, _G.main);
37893800
return _G;
37903801
};
3791-
var ____x116 = typeof(window);
3792-
if ("undefined" === ____x116) {
3802+
var ____x117 = typeof(window);
3803+
if ("undefined" === ____x117) {
37933804
module.exports.create = create;
37943805
} else {
37953806
if (true) {

lib.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
(set (module .exports .create) create))
3333
(else
3434
(when-compiling
35-
`(%literal ,(escape (system .read-file "vm.js" .replace |/[\r]/g| ""))))
35+
`(%literal ,(escape (system .read-file "vm.js"))))
3636
(unless (window .require)
3737
(set (window .require) (fn (x) (window .DAX .shims [x]))))
3838
(set (window .DAX)

system.l

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
(define path (require "path"))
44
(define process (require "process"))
55

6-
(define read-file (path)
7-
(fs .read-file-sync path "utf8"))
6+
(define read-file (path (o mode 'text))
7+
(if (= mode 'text)
8+
(fs .read-file-sync path "utf8" .replace |/\r/g| "")
9+
(fs .read-file-sync path)))
810

911
(define write-file (path data)
1012
(fs .write-file-sync path data "utf8"))

0 commit comments

Comments
 (0)