diff options
Diffstat (limited to 'src/lzio.js')
-rw-r--r-- | src/lzio.js | 29 |
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; |