@pezkuwi/wasm-util 7.5.7 → 7.5.8

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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- ## @polkadot/wasm-util
1
+ ## @pezkuwi/wasm-util
2
2
 
3
- Wasm utility functions, used internally in `@polkadot/wasm-crypto`.
3
+ Wasm utility functions, used internally in `@pezkuwi/wasm-crypto`.
package/package.json CHANGED
@@ -1,136 +1,31 @@
1
1
  {
2
2
  "author": "Jaco Greeff <jacogr@gmail.com>",
3
- "bugs": "https://github.com/pezkuwi-js/wasm/issues",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-wasm/issues",
4
4
  "description": "Utilities used exclusively inside Wasm decoding",
5
5
  "engines": {
6
6
  "node": ">=18"
7
7
  },
8
- "homepage": "https://github.com/pezkuwi-js/wasm/tree/master/packages/wasm-util#readme",
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-wasm/tree/master/packages/wasm-util#readme",
9
9
  "license": "Apache-2.0",
10
10
  "name": "@pezkuwi/wasm-util",
11
11
  "repository": {
12
12
  "directory": "packages/wasm-util",
13
13
  "type": "git",
14
- "url": "https://github.com/pezkuwi-js/wasm.git"
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-wasm.git"
15
15
  },
16
16
  "sideEffects": [
17
17
  "./packageDetect.js",
18
- "./cjs/packageDetect.js"
18
+ "./packageDetect.cjs"
19
19
  ],
20
20
  "type": "module",
21
- "version": "7.5.7",
22
- "main": "./cjs/index.js",
23
- "module": "./index.js",
24
- "types": "./index.d.ts",
25
- "exports": {
26
- "./cjs/package.json": "./cjs/package.json",
27
- "./cjs/*": "./cjs/*.js",
28
- ".": {
29
- "module": {
30
- "types": "./index.d.ts",
31
- "default": "./index.js"
32
- },
33
- "require": {
34
- "types": "./cjs/index.d.ts",
35
- "default": "./cjs/index.js"
36
- },
37
- "default": {
38
- "types": "./index.d.ts",
39
- "default": "./index.js"
40
- }
41
- },
42
- "./base64": {
43
- "module": {
44
- "types": "./base64.d.ts",
45
- "default": "./base64.js"
46
- },
47
- "require": {
48
- "types": "./cjs/base64.d.ts",
49
- "default": "./cjs/base64.js"
50
- },
51
- "default": {
52
- "types": "./base64.d.ts",
53
- "default": "./base64.js"
54
- }
55
- },
56
- "./bundle": {
57
- "module": {
58
- "types": "./bundle.d.ts",
59
- "default": "./bundle.js"
60
- },
61
- "require": {
62
- "types": "./cjs/bundle.d.ts",
63
- "default": "./cjs/bundle.js"
64
- },
65
- "default": {
66
- "types": "./bundle.d.ts",
67
- "default": "./bundle.js"
68
- }
69
- },
70
- "./fflate": {
71
- "module": {
72
- "types": "./fflate.d.ts",
73
- "default": "./fflate.js"
74
- },
75
- "require": {
76
- "types": "./cjs/fflate.d.ts",
77
- "default": "./cjs/fflate.js"
78
- },
79
- "default": {
80
- "types": "./fflate.d.ts",
81
- "default": "./fflate.js"
82
- }
83
- },
84
- "./package.json": {
85
- "require": "./cjs/package.json",
86
- "default": "./package.json"
87
- },
88
- "./packageDetect": {
89
- "module": {
90
- "types": "./packageDetect.d.ts",
91
- "default": "./packageDetect.js"
92
- },
93
- "require": {
94
- "types": "./cjs/packageDetect.d.ts",
95
- "default": "./cjs/packageDetect.js"
96
- },
97
- "default": {
98
- "types": "./packageDetect.d.ts",
99
- "default": "./packageDetect.js"
100
- }
101
- },
102
- "./packageInfo.js": {
103
- "module": {
104
- "types": "./packageInfo.d.ts",
105
- "default": "./packageInfo.js"
106
- },
107
- "require": {
108
- "types": "./cjs/packageInfo.d.ts",
109
- "default": "./cjs/packageInfo.js"
110
- },
111
- "default": {
112
- "types": "./packageInfo.d.ts",
113
- "default": "./packageInfo.js"
114
- }
115
- },
116
- "./packageInfo": {
117
- "module": {
118
- "types": "./packageInfo.d.ts",
119
- "default": "./packageInfo.js"
120
- },
121
- "require": {
122
- "types": "./cjs/packageInfo.d.ts",
123
- "default": "./cjs/packageInfo.js"
124
- },
125
- "default": {
126
- "types": "./packageInfo.d.ts",
127
- "default": "./packageInfo.js"
128
- }
129
- }
130
- },
21
+ "version": "7.5.8",
22
+ "main": "index.js",
131
23
  "dependencies": {
132
24
  "tslib": "^2.7.0"
133
25
  },
26
+ "devDependencies": {
27
+ "@pezkuwi/util": "^14.0.1"
28
+ },
134
29
  "peerDependencies": {
135
30
  "@pezkuwi/util": "*"
136
31
  }
@@ -0,0 +1,46 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
+
6
+ import { base64Decode } from './base64.js';
7
+
8
+ const TESTS = [
9
+ {
10
+ // hello world Приветствую ми 你好
11
+ base64: 'aGVsbG8gd29ybGQg0J/RgNC40LLQtdGC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==',
12
+ output: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 209, 129, 209, 130, 208, 178, 209, 131, 209, 142, 32, 208, 188, 208, 184, 32, 228, 189, 160, 229, 165, 189])
13
+ },
14
+ {
15
+ // ✓ à la mode
16
+ base64: '4pyTIMOgIGxhIG1vZGU=',
17
+ output: new Uint8Array([226, 156, 147, 32, 195, 160, 32, 108, 97, 32, 109, 111, 100, 101])
18
+ },
19
+ {
20
+ // Hello World!
21
+ base64: 'SGVsbG8gV29ybGQh',
22
+ output: new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
23
+ },
24
+ {
25
+ base64: 'AA==',
26
+ output: new Uint8Array([0])
27
+ },
28
+ {
29
+ base64: 'AAA=',
30
+ output: new Uint8Array([0, 0])
31
+ },
32
+ {
33
+ base64: 'AAAA',
34
+ output: new Uint8Array([0, 0, 0])
35
+ }
36
+ ];
37
+
38
+ describe('base64Decode', (): void => {
39
+ for (const { base64, output } of TESTS) {
40
+ it(`decodes ${base64}`, (): void => {
41
+ expect(
42
+ base64Decode(base64, new Uint8Array(output.length))
43
+ ).toEqual(output);
44
+ });
45
+ }
46
+ });
package/src/base64.ts ADDED
@@ -0,0 +1,43 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Use an array for our indexer - this is faster than using map access. In
5
+ // this case we assume ASCII-only inputs, so we cannot overflow the array
6
+ const CHR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' as const;
7
+ const map = new Array<number>(256);
8
+
9
+ // We use charCodeAt for access here and in the decoder loop - this is faster
10
+ // on lookups (array + numbers) and also faster than accessing the specific
11
+ // character via data[i]
12
+ for (let i = 0, count = CHR.length; i < count; i++) {
13
+ map[CHR.charCodeAt(i)] = i;
14
+ }
15
+
16
+ /**
17
+ * @name base64Decode
18
+ * @description
19
+ * A base64 decoding function that operates in all environments. Unlike decoding
20
+ * from Buffer (Node.js only) or atob (browser-only) this implementation is
21
+ * slightly slower, but it is platform independent.
22
+ *
23
+ * For our usage, since we have access to the static final size, so we decode
24
+ * to a specified output buffer. This also means we have applied a number of
25
+ * optimizations based on this - checking output position instead of chars.
26
+ */
27
+ export function base64Decode (data: string, out: Uint8Array): Uint8Array {
28
+ let byte = 0;
29
+ let bits = 0;
30
+ let pos = -1;
31
+
32
+ for (let i = 0, last = out.length - 1; pos !== last; i++) {
33
+ // each character represents 6 bits
34
+ byte = (byte << 6) | map[data.charCodeAt(i)];
35
+
36
+ // each byte needs to contain 8 bits
37
+ if ((bits += 6) >= 8) {
38
+ out[++pos] = (byte >>> (bits -= 8)) & 0xff;
39
+ }
40
+ }
41
+
42
+ return out;
43
+ }
@@ -1,3 +1,6 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  export { base64Decode } from './base64.js';
2
5
  export { unzlibSync } from './fflate.js';
3
6
  export { packageInfo } from './packageInfo.js';
package/src/fflate.ts ADDED
@@ -0,0 +1,349 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // MIT License
5
+ //
6
+ // Copyright (c) 2020 Arjun Barrett
7
+ //
8
+ // Copied from https://github.com/101arrowz/fflate/blob/73c737941ec89d85cdf0ad39ee6f26c5fdc95fd7/src/index.ts
9
+ // This only contains the unzlibSync function, no compression, no async, no workers
10
+ //
11
+ // These 2 issues are addressed as a short-term, stop-gap solution
12
+ // - https://github.com/pezkuwi/api/issues/2963
13
+ // - https://github.com/101arrowz/fflate/issues/17
14
+ //
15
+ // Only tweaks made here are some TS adjustments (we use strict null checks),
16
+ // the code is otherwise as-is with only the single required function provided
17
+ // (compression is still being done in the build with fflate)
18
+
19
+ /* eslint-disable */
20
+
21
+ // inflate state
22
+ type InflateState = {
23
+ // lmap
24
+ l?: Uint16Array | undefined;
25
+ // dmap
26
+ d?: Uint16Array | undefined;
27
+ // lbits
28
+ m?: number | undefined;
29
+ // dbits
30
+ n?: number | undefined;
31
+ // final
32
+ f?: number;
33
+ // pos
34
+ p?: number;
35
+ // byte
36
+ b?: number;
37
+ // lstchk
38
+ i?: boolean;
39
+ };
40
+
41
+ // aliases for shorter compressed code (most minifers don't do this)
42
+ const u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;
43
+
44
+ // code length index map
45
+ const clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
46
+
47
+ // fixed length extra bits
48
+ const fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
49
+
50
+ // fixed distance extra bits
51
+ // see fleb note
52
+ const fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
53
+
54
+ // get base, reverse index map from extra bits
55
+ const freb = (eb: Uint8Array, start: number) => {
56
+ const b = new u16(31);
57
+ for (let i = 0; i < 31; ++i) {
58
+ b[i] = start += 1 << eb[i - 1];
59
+ }
60
+ // numbers here are at max 18 bits
61
+ const r = new u32(b[30]);
62
+ for (let i = 1; i < 30; ++i) {
63
+ for (let j = b[i]; j < b[i + 1]; ++j) {
64
+ r[j] = ((j - b[i]) << 5) | i;
65
+ }
66
+ }
67
+ return [b, r] as const;
68
+ }
69
+
70
+ const [fl, revfl] = freb(fleb, 2);
71
+ // we can ignore the fact that the other numbers are wrong; they never happen anyway
72
+ fl[28] = 258, revfl[258] = 28;
73
+ const [fd] = freb(fdeb, 0);
74
+
75
+ // map of value to reverse (assuming 16 bits)
76
+ const rev = new u16(32768);
77
+ for (let i = 0; i < 32768; ++i) {
78
+ // reverse table algorithm from SO
79
+ let x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);
80
+ x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);
81
+ x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);
82
+ rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;
83
+ }
84
+
85
+ // create huffman tree from u8 "map": index -> code length for code index
86
+ // mb (max bits) must be at most 15
87
+ // TODO: optimize/split up?
88
+ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
89
+ const s = cd.length;
90
+ // index
91
+ let i = 0;
92
+ // u16 "map": index -> # of codes with bit length = index
93
+ const l = new u16(mb);
94
+ // length of cd must be 288 (total # of codes)
95
+ for (; i < s; ++i) {
96
+ if (cd[i]) ++l[cd[i] - 1];
97
+ }
98
+ // u16 "map": index -> minimum code for bit length = index
99
+ const le = new u16(mb);
100
+ for (i = 1; i < mb; ++i) {
101
+ le[i] = (le[i - 1] + l[i - 1]) << 1;
102
+ }
103
+ let co: Uint16Array;
104
+ if (r) {
105
+ // u16 "map": index -> number of actual bits, symbol for code
106
+ co = new u16(1 << mb);
107
+ // bits to remove for reverser
108
+ const rvb = 15 - mb;
109
+ for (i = 0; i < s; ++i) {
110
+ // ignore 0 lengths
111
+ if (cd[i]) {
112
+ // num encoding both symbol and bits read
113
+ const sv = (i << 4) | cd[i];
114
+ // free bits
115
+ const r = mb - cd[i];
116
+ // start value
117
+ let v = le[cd[i] - 1]++ << r;
118
+ // m is end value
119
+ for (const m = v | ((1 << r) - 1); v <= m; ++v) {
120
+ // every 16 bit value starting with the code yields the same result
121
+ co[rev[v] >> rvb] = sv;
122
+ }
123
+ }
124
+ }
125
+ } else {
126
+ co = new u16(s);
127
+ for (i = 0; i < s; ++i) {
128
+ if (cd[i]) {
129
+ co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
130
+ }
131
+ }
132
+ }
133
+ return co;
134
+ });
135
+
136
+ // fixed length tree
137
+ const flt = new u8(288);
138
+ for (let i = 0; i < 144; ++i) flt[i] = 8;
139
+ for (let i = 144; i < 256; ++i) flt[i] = 9;
140
+ for (let i = 256; i < 280; ++i) flt[i] = 7;
141
+ for (let i = 280; i < 288; ++i) flt[i] = 8;
142
+ // fixed distance tree
143
+ const fdt = new u8(32);
144
+ for (let i = 0; i < 32; ++i) fdt[i] = 5;
145
+
146
+ // fixed length map
147
+ const flrm = hMap(flt, 9, 1);
148
+ // fixed distance map
149
+ const fdrm = hMap(fdt, 5, 1);
150
+
151
+ // read d, starting at bit p and mask with m
152
+ const bits = (d: Uint8Array, p: number, m: number) => {
153
+ const o = p >>> 3;
154
+ return ((d[o] | (d[o + 1] << 8)) >>> (p & 7)) & m;
155
+ }
156
+
157
+ // read d, starting at bit p continuing for at least 16 bits
158
+ const bits16 = (d: Uint8Array, p: number) => {
159
+ const o = p >>> 3;
160
+ return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >>> (p & 7));
161
+ }
162
+
163
+ // get end of byte
164
+ const shft = (p: number) => (p >>> 3) + (p & 7 && 1);
165
+
166
+ // typed array slice - allows garbage collector to free original reference,
167
+ // while being more compatible than .slice
168
+ const slc = <T extends Uint8Array | Uint16Array | Uint32Array>(v: T, s: number, e?: number): T => {
169
+ if (s == null || s < 0) s = 0;
170
+ if (e == null || e > v.length) e = v.length;
171
+ // can't use .constructor in case user-supplied
172
+ const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s) as T;
173
+ n.set(v.subarray(s, e));
174
+ return n;
175
+ }
176
+
177
+ // find max of array
178
+ const max = (a: Uint8Array | number[]) => {
179
+ let m = a[0];
180
+ for (let i = 1, count = a.length; i < count; ++i) {
181
+ if (a[i] > m) m = a[i];
182
+ }
183
+ return m;
184
+ };
185
+
186
+ // expands raw DEFLATE data
187
+ const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
188
+ const noSt = !st || st.i;
189
+ if (!st) st = {};
190
+ // source length
191
+ const sl = dat.length;
192
+ // have to estimate size
193
+ const noBuf = !buf || !noSt;
194
+ // Assumes roughly 33% compression ratio average
195
+ if (!buf) buf = new u8(sl * 3);
196
+ // ensure buffer can fit at least l elements
197
+ const cbuf = (l: number) => {
198
+ let bl = buf!.length;
199
+ // need to increase size to fit
200
+ if (l > bl) {
201
+ // Double or set to necessary, whichever is greater
202
+ const nbuf = new u8(Math.max(bl << 1, l));
203
+ nbuf.set(buf!);
204
+ buf = nbuf;
205
+ }
206
+ };
207
+ // last chunk bitpos bytes
208
+ let final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
209
+ if (final && !lm) return buf;
210
+ // total bits
211
+ const tbts = sl << 3;
212
+ do {
213
+ if (!lm) {
214
+ // BFINAL - this is only 1 when last chunk is next
215
+ st.f = final = bits(dat, pos, 1);
216
+ // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
217
+ const type = bits(dat, pos + 1, 3);
218
+ pos += 3;
219
+ if (!type) {
220
+ // go to end of byte boundary
221
+ const s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
222
+ if (t > sl) {
223
+ if (noSt) throw 'unexpected EOF';
224
+ break;
225
+ }
226
+ // ensure size
227
+ if (noBuf) cbuf(bt + l);
228
+ // Copy over uncompressed data
229
+ buf.set(dat.subarray(s, t), bt);
230
+ // Get new bitpos, update byte count
231
+ st.b = bt += l, st.p = pos = t << 3;
232
+ continue;
233
+ }
234
+ else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
235
+ else if (type == 2) {
236
+ // literal lengths
237
+ const hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
238
+ const tl = hLit + bits(dat, pos + 5, 31) + 1;
239
+ pos += 14;
240
+ // length+distance tree
241
+ const ldt = new u8(tl);
242
+ // code length tree
243
+ const clt = new u8(19);
244
+ for (let i = 0; i < hcLen; ++i) {
245
+ // use index map to get real code
246
+ clt[clim[i]] = bits(dat, pos + i * 3, 7);
247
+ }
248
+ pos += hcLen * 3;
249
+ // code lengths bits
250
+ const clb = max(clt), clbmsk = (1 << clb) - 1;
251
+ if (!noSt && pos + tl * (clb + 7) > tbts) break;
252
+ // code lengths map
253
+ const clm = hMap(clt, clb, 1);
254
+ for (let i = 0; i < tl;) {
255
+ const r = clm[bits(dat, pos, clbmsk)];
256
+ // bits read
257
+ pos += r & 15;
258
+ // symbol
259
+ const s = r >>> 4;
260
+ // code length to copy
261
+ if (s < 16) {
262
+ ldt[i++] = s;
263
+ } else {
264
+ // copy count
265
+ let c = 0, n = 0;
266
+ if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
267
+ else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;
268
+ else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
269
+ while (n--) ldt[i++] = c;
270
+ }
271
+ }
272
+ // length tree distance tree
273
+ const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
274
+ // max length bits
275
+ lbt = max(lt);
276
+ // max dist bits
277
+ dbt = max(dt);
278
+ lm = hMap(lt, lbt, 1);
279
+ dm = hMap(dt, dbt, 1);
280
+ } else throw 'invalid block type';
281
+ if (pos > tbts) throw 'unexpected EOF';
282
+ }
283
+ // Make sure the buffer can hold this + the largest possible addition
284
+ // maximum chunk size (practically, theoretically infinite) is 2^17;
285
+ if (noBuf) cbuf(bt + 131072);
286
+ const lms = (1 << lbt!) - 1, dms = (1 << dbt!) - 1;
287
+ const mxa = lbt! + dbt! + 18;
288
+ while (noSt || pos + mxa < tbts) {
289
+ // bits read, code
290
+ const c = lm[bits16(dat, pos) & lms], sym = c >>> 4;
291
+ pos += c & 15;
292
+ if (pos > tbts) throw 'unexpected EOF';
293
+ if (!c) throw 'invalid length/literal';
294
+ if (sym < 256) buf[bt++] = sym;
295
+ else if (sym == 256) {
296
+ lm = undefined;
297
+ break;
298
+ }
299
+ else {
300
+ let add = sym - 254;
301
+ // no extra bits needed if less
302
+ if (sym > 264) {
303
+ // index
304
+ const i = sym - 257, b = fleb[i];
305
+ add = bits(dat, pos, (1 << b) - 1) + fl[i];
306
+ pos += b;
307
+ }
308
+ // dist
309
+ const d = dm![bits16(dat, pos) & dms], dsym = d >>> 4;
310
+ if (!d) throw 'invalid distance';
311
+ pos += d & 15;
312
+ let dt = fd[dsym];
313
+ if (dsym > 3) {
314
+ const b = fdeb[dsym];
315
+ dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;
316
+ }
317
+ if (pos > tbts) throw 'unexpected EOF';
318
+ if (noBuf) cbuf(bt + 131072);
319
+ const end = bt + add;
320
+ for (; bt < end; bt += 4) {
321
+ buf[bt] = buf[bt - dt];
322
+ buf[bt + 1] = buf[bt + 1 - dt];
323
+ buf[bt + 2] = buf[bt + 2 - dt];
324
+ buf[bt + 3] = buf[bt + 3 - dt];
325
+ }
326
+ bt = end;
327
+ }
328
+ }
329
+ st.l = lm, st.p = pos, st.b = bt;
330
+ if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
331
+ } while (!final);
332
+ return bt == buf.length ? buf : slc(buf, 0, bt);
333
+ }
334
+
335
+ // zlib valid
336
+ const zlv = (d: Uint8Array) => {
337
+ if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31)) throw 'invalid zlib data';
338
+ if (d[1] & 32) throw 'invalid zlib data: preset dictionaries not supported';
339
+ }
340
+
341
+ /**
342
+ * Expands Zlib data
343
+ * @param data The data to decompress
344
+ * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
345
+ * @returns The decompressed version of the data
346
+ */
347
+ export function unzlibSync(data: Uint8Array, out?: Uint8Array) {
348
+ return inflt((zlv(data), data.subarray(2, -4)), out);
349
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import './packageDetect.js';
5
+
6
+ export * from './bundle.js';
package/src/mod.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './index.js';
@@ -0,0 +1,11 @@
1
+ // Copyright 2017-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @pezkuwi/dev
5
+ // (packageInfo imports will be kept as-is, user-editable)
6
+
7
+ import { detectPackage } from '@pezkuwi/util';
8
+
9
+ import { packageInfo } from './packageInfo.js';
10
+
11
+ detectPackage(packageInfo, null, []);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2026 @pezkuwi/wasm-util authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @pezkuwi/dev
5
+
6
+ export const packageInfo = { name: '@pezkuwi/wasm-util', path: 'auto', type: 'auto', version: '7.5.4' };
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "exclude": [
9
+ "**/mod.ts",
10
+ "**/*.spec.ts",
11
+ ],
12
+ "references": []
13
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src",
7
+ "emitDeclarationOnly": false,
8
+ "noEmit": true
9
+ },
10
+ "include": [
11
+ "**/*.spec.ts"
12
+ ],
13
+ "references": [
14
+ { "path": "../wasm-util/tsconfig.build.json" }
15
+ ]
16
+ }