diff options
author | daurnimator <quae@daurnimator.com> | 2018-04-06 22:32:34 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-04-06 22:32:34 +1000 |
commit | 3fdb709d2c65659180150bc4253945fd0ac5fbad (patch) | |
tree | a3ade9b0e722bde590c1f6c728e08094bee844b8 | |
parent | 8b2d34d2abde706ce0b7320c95bf2627970f1bdf (diff) | |
download | fengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.tar.gz fengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.tar.bz2 fengari-3fdb709d2c65659180150bc4253945fd0ac5fbad.zip |
src/liolib.js: fs.writeSync in node 6 doesn't take a Uint8Array
-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; |