From 3fdb709d2c65659180150bc4253945fd0ac5fbad Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 6 Apr 2018 22:32:34 +1000 Subject: src/liolib.js: fs.writeSync in node 6 doesn't take a Uint8Array --- NEWS | 5 +++++ src/liolib.js | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 28a9d71..fbb983b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +UNRELEASED + + - More node 6 compatibility fixes + + 0.1.1 - 2018-04-03 - Fix node 6 compatibility 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; -- cgit v1.2.3-54-g00ecf