summaryrefslogtreecommitdiff
path: root/src/lzio.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-15 14:57:13 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-15 14:57:13 +1100
commite0e5d05626fcd6cb4622abcaae9fc951d9ae91b1 (patch)
tree49531b2a69c166ad193adddf50edbadb5e1a91a1 /src/lzio.js
parent6099ba186c38c854332ec483edd6cbca3cf94871 (diff)
parent8249248f80467f1660509a30623f40bb9ff1eba7 (diff)
downloadfengari-e0e5d05626fcd6cb4622abcaae9fc951d9ae91b1.tar.gz
fengari-e0e5d05626fcd6cb4622abcaae9fc951d9ae91b1.tar.bz2
fengari-e0e5d05626fcd6cb4622abcaae9fc951d9ae91b1.zip
Merge branch 'Uint8Array'
Diffstat (limited to 'src/lzio.js')
-rw-r--r--src/lzio.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/lzio.js b/src/lzio.js
index 3d877aa..a00a24b 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 {
@@ -42,22 +48,15 @@ class ZIO {
const EOZ = -1;
const luaZ_fill = function(z) {
- let size;
let buff = z.reader(z.L, z.data);
if (buff === null)
return EOZ;
- if (buff instanceof DataView) {
- z.buffer = new Uint8Array(buff.buffer, buff.byteOffset, buff.byteLength);
- z.off = 0;
- size = buff.byteLength - buff.byteOffset;
- } else {
- assert(typeof buff !== "string", "Should only load binary of array of bytes");
- z.buffer = buff;
- z.off = 0;
- size = buff.length;
- }
+ assert(buff instanceof Uint8Array, "Should only load binary of array of bytes");
+ let size = buff.length;
if (size === 0)
return EOZ;
+ z.buffer = buff;
+ z.off = 0;
z.n = size - 1;
return z.buffer[z.off++];
};
@@ -87,11 +86,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;