diff options
author | daurnimator <quae@daurnimator.com> | 2017-12-13 17:21:59 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-12-15 14:53:01 +1100 |
commit | 55ff446d1fdd5ad5982e2ce3f7118fca8c16880b (patch) | |
tree | fcdd5eff874d57dff5e38eae219c5609c1fc1a50 /src | |
parent | af95e27d1b2d5f0f39534523778003dfd1fcf417 (diff) | |
download | fengari-55ff446d1fdd5ad5982e2ce3f7118fca8c16880b.tar.gz fengari-55ff446d1fdd5ad5982e2ce3f7118fca8c16880b.tar.bz2 fengari-55ff446d1fdd5ad5982e2ce3f7118fca8c16880b.zip |
src/lauxlib.js: Use a Uint8Array for luaL_loadfilex in both browser and node
Diffstat (limited to 'src')
-rw-r--r-- | src/lauxlib.js | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js index 3b2be6e..5687242 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -713,7 +713,7 @@ class LoadF { constructor() { this.n = NaN; /* number of pre-read characters */ this.f = null; /* file being read */ - this.buff = typeof process === "undefined" ? new Array(1024) : new Buffer(1024); /* area for reading file */ + this.buff = new Uint8Array(1024); /* area for reading file */ this.pos = 0; /* current position in file */ this.err = void 0; } @@ -726,8 +726,8 @@ if (typeof process === "undefined") { if (lf.f !== null && lf.n > 0) { /* are there pre-read characters to be read? */ let bytes = lf.n; /* return them (chars already in buffer) */ lf.n = 0; /* no more pre-read characters */ - lf.f = lf.f.slice(lf.pos); /* we won't use lf.buff anymore */ - return lf.buff.slice(0, bytes); + lf.f = lf.f.subarray(lf.pos); /* we won't use lf.buff anymore */ + return lf.buff.subarray(0, bytes); } let f = lf.f; @@ -789,7 +789,6 @@ if (typeof process === "undefined") { bytes = lf.n; /* return them (chars already in buffer) */ lf.n = 0; /* no more pre-read characters */ } else { /* read a block from file */ - lf.buff.fill(0); try { bytes = fs.readSync(lf.f, lf.buff, 0, lf.buff.length, lf.pos); /* read block */ } catch(e) { @@ -799,7 +798,7 @@ if (typeof process === "undefined") { lf.pos += bytes; } if (bytes > 0) - return lf.buff.slice(0, bytes); /* slice on a node.js Buffer is 'free' */ + return lf.buff.subarray(0, bytes); /* slice on a node.js Buffer is 'free' */ else return null; }; |