summaryrefslogtreecommitdiff
path: root/src/lzio.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-13 14:55:33 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-13 15:31:04 +1100
commit11a2421acaf2b39d19ee99933102c35e28fd13f8 (patch)
tree4abd1fa6ee063f75c634349a02702de7bc145a8b /src/lzio.js
parent3e7c102eefbaae9e6bc839b11bba79aee1c5e040 (diff)
downloadfengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.tar.gz
fengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.tar.bz2
fengari-11a2421acaf2b39d19ee99933102c35e28fd13f8.zip
Use Uint8Array to back strings
Diffstat (limited to 'src/lzio.js')
-rw-r--r--src/lzio.js29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/lzio.js b/src/lzio.js
index 3d877aa..efd7909 100644
--- a/src/lzio.js
+++ b/src/lzio.js
@@ -11,7 +11,7 @@ class MBuffer {
}
const luaZ_buffer = function(buff) {
- return buff.buffer;
+ return buff.buffer.subarray(0, buff.n);
};
const luaZ_buffremove = function(buff, i) {
@@ -20,7 +20,13 @@ const luaZ_buffremove = function(buff, i) {
const luaZ_resetbuffer = function(buff) {
buff.n = 0;
- buff.buffer = [];
+};
+
+const luaZ_resizebuffer = function(L, buff, size) {
+ let newbuff = new Uint8Array(size);
+ if (buff.buffer)
+ newbuff.set(buff.buffer);
+ buff.buffer = newbuff;
};
class ZIO {
@@ -51,7 +57,7 @@ const luaZ_fill = function(z) {
z.off = 0;
size = buff.byteLength - buff.byteOffset;
} else {
- assert(typeof buff !== "string", "Should only load binary of array of bytes");
+ assert(buff instanceof Uint8Array, "Should only load binary of array of bytes");
z.buffer = buff;
z.off = 0;
size = buff.length;
@@ -87,11 +93,12 @@ const luaZ_read = function(z, b, b_offset, n) {
return 0;
};
-module.exports.EOZ = EOZ;
-module.exports.luaZ_buffer = luaZ_buffer;
-module.exports.luaZ_buffremove = luaZ_buffremove;
-module.exports.luaZ_fill = luaZ_fill;
-module.exports.luaZ_read = luaZ_read;
-module.exports.luaZ_resetbuffer = luaZ_resetbuffer;
-module.exports.MBuffer = MBuffer;
-module.exports.ZIO = ZIO;
+module.exports.EOZ = EOZ;
+module.exports.luaZ_buffer = luaZ_buffer;
+module.exports.luaZ_buffremove = luaZ_buffremove;
+module.exports.luaZ_fill = luaZ_fill;
+module.exports.luaZ_read = luaZ_read;
+module.exports.luaZ_resetbuffer = luaZ_resetbuffer;
+module.exports.luaZ_resizebuffer = luaZ_resizebuffer;
+module.exports.MBuffer = MBuffer;
+module.exports.ZIO = ZIO;