diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | src/liolib.js | 7 |
2 files changed, 11 insertions, 1 deletions
@@ -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; |