aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-04-06 22:32:34 +1000
committerdaurnimator <quae@daurnimator.com>2018-04-06 22:32:34 +1000
commit3fdb709d2c65659180150bc4253945fd0ac5fbad (patch)
treea3ade9b0e722bde590c1f6c728e08094bee844b8 /src
parent8b2d34d2abde706ce0b7320c95bf2627970f1bdf (diff)
downloadfengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.tar.gz
fengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.tar.bz2
fengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.zip
src/liolib.js: fs.writeSync in node 6 doesn't take a Uint8Array
Diffstat (limited to 'src')
-rw-r--r--src/liolib.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/liolib.js b/src/liolib.js
index bd78f87..7f0fff0 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -130,6 +130,11 @@ const io_output = function(L) {
return g_iofile(L, IO_OUTPUT, "w");
};
+/* node <= 6 doesn't support passing a Uint8Array to fs.writeSync */
+const prepare_string_for_write = process.versions.node > 6 ?
+ (s) => s : // identity function
+ (s) => Buffer.from(s.buffer, s.byteOffset, s.byteLength);
+
const g_write = function(L, f, arg) {
let nargs = lua_gettop(L) - arg;
let status = true;
@@ -137,7 +142,7 @@ const g_write = function(L, f, arg) {
for (; nargs--; arg++) {
let s = luaL_checklstring(L, arg);
try {
- status = status && (fs.writeSync(f.fd, Uint8Array.from(s)) === s.length);
+ status = status && (fs.writeSync(f.fd, prepare_string_for_write(s)) === s.length);
} catch (e) {
status = false;
err = e;