m-bus-parser-wasm-pack 0.0.6 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,22 +15,18 @@ function getUint8ArrayMemory0() {
15
15
  return cachedUint8ArrayMemory0;
16
16
  }
17
17
 
18
- const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
18
+ const cachedTextEncoder = new TextEncoder();
19
19
 
20
- let cachedTextEncoder = new lTextEncoder('utf-8');
21
-
22
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
23
- ? function (arg, view) {
24
- return cachedTextEncoder.encodeInto(arg, view);
20
+ if (!('encodeInto' in cachedTextEncoder)) {
21
+ cachedTextEncoder.encodeInto = function (arg, view) {
22
+ const buf = cachedTextEncoder.encode(arg);
23
+ view.set(buf);
24
+ return {
25
+ read: arg.length,
26
+ written: buf.length
27
+ };
28
+ }
25
29
  }
26
- : function (arg, view) {
27
- const buf = cachedTextEncoder.encode(arg);
28
- view.set(buf);
29
- return {
30
- read: arg.length,
31
- written: buf.length
32
- };
33
- });
34
30
 
35
31
  function passStringToWasm0(arg, malloc, realloc) {
36
32
 
@@ -61,7 +57,7 @@ function passStringToWasm0(arg, malloc, realloc) {
61
57
  }
62
58
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
63
59
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
64
- const ret = encodeString(arg, view);
60
+ const ret = cachedTextEncoder.encodeInto(arg, view);
65
61
 
66
62
  offset += ret.written;
67
63
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -71,15 +67,25 @@ function passStringToWasm0(arg, malloc, realloc) {
71
67
  return ptr;
72
68
  }
73
69
 
74
- const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
75
-
76
- let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
70
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
77
71
 
78
72
  cachedTextDecoder.decode();
79
73
 
74
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
75
+ let numBytesDecoded = 0;
76
+ function decodeText(ptr, len) {
77
+ numBytesDecoded += len;
78
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
79
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
80
+ cachedTextDecoder.decode();
81
+ numBytesDecoded = len;
82
+ }
83
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
84
+ }
85
+
80
86
  function getStringFromWasm0(ptr, len) {
81
87
  ptr = ptr >>> 0;
82
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
88
+ return decodeText(ptr, len);
83
89
  }
84
90
  /**
85
91
  * @param {string} data
@@ -104,7 +110,7 @@ export function m_bus_parse(data, format) {
104
110
  }
105
111
 
106
112
  export function __wbindgen_init_externref_table() {
107
- const table = wasm.__wbindgen_export_0;
113
+ const table = wasm.__wbindgen_externrefs;
108
114
  const offset = table.grow(4);
109
115
  table.set(0, undefined);
110
116
  table.set(offset + 0, undefined);
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Michael Aebli"
6
6
  ],
7
7
  "description": "A wasm-pack to use the library for parsing M-Bus frames",
8
- "version": "0.0.6",
8
+ "version": "0.0.11",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",