@pezkuwi/wasm-util 7.5.9 → 7.5.10

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/base64.js ADDED
@@ -0,0 +1,30 @@
1
+ const CHR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
+ const map = new Array(256);
3
+ for (let i = 0, count = CHR.length; i < count; i++) {
4
+ map[CHR.charCodeAt(i)] = i;
5
+ }
6
+ /**
7
+ * @name base64Decode
8
+ * @description
9
+ * A base64 decoding function that operates in all environments. Unlike decoding
10
+ * from Buffer (Node.js only) or atob (browser-only) this implementation is
11
+ * slightly slower, but it is platform independent.
12
+ *
13
+ * For our usage, since we have access to the static final size, so we decode
14
+ * to a specified output buffer. This also means we have applied a number of
15
+ * optimizations based on this - checking output position instead of chars.
16
+ */
17
+ export function base64Decode(data, out) {
18
+ let byte = 0;
19
+ let bits = 0;
20
+ let pos = -1;
21
+ for (let i = 0, last = out.length - 1; pos !== last; i++) {
22
+ // each character represents 6 bits
23
+ byte = (byte << 6) | map[data.charCodeAt(i)];
24
+ // each byte needs to contain 8 bits
25
+ if ((bits += 6) >= 8) {
26
+ out[++pos] = (byte >>> (bits -= 8)) & 0xff;
27
+ }
28
+ }
29
+ return out;
30
+ }
@@ -1,6 +1,3 @@
1
- // Copyright 2019-2026 @pezkuwi/wasm-util authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  export { base64Decode } from './base64.js';
5
2
  export { unzlibSync } from './fflate.js';
6
3
  export { packageInfo } from './packageInfo.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @name base64Decode
3
+ * @description
4
+ * A base64 decoding function that operates in all environments. Unlike decoding
5
+ * from Buffer (Node.js only) or atob (browser-only) this implementation is
6
+ * slightly slower, but it is platform independent.
7
+ *
8
+ * For our usage, since we have access to the static final size, so we decode
9
+ * to a specified output buffer. This also means we have applied a number of
10
+ * optimizations based on this - checking output position instead of chars.
11
+ */
12
+ export declare function base64Decode(data: string, out: Uint8Array): Uint8Array;
package/cjs/base64.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64Decode = base64Decode;
4
+ const CHR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
+ const map = new Array(256);
6
+ for (let i = 0, count = CHR.length; i < count; i++) {
7
+ map[CHR.charCodeAt(i)] = i;
8
+ }
9
+ /**
10
+ * @name base64Decode
11
+ * @description
12
+ * A base64 decoding function that operates in all environments. Unlike decoding
13
+ * from Buffer (Node.js only) or atob (browser-only) this implementation is
14
+ * slightly slower, but it is platform independent.
15
+ *
16
+ * For our usage, since we have access to the static final size, so we decode
17
+ * to a specified output buffer. This also means we have applied a number of
18
+ * optimizations based on this - checking output position instead of chars.
19
+ */
20
+ function base64Decode(data, out) {
21
+ let byte = 0;
22
+ let bits = 0;
23
+ let pos = -1;
24
+ for (let i = 0, last = out.length - 1; pos !== last; i++) {
25
+ // each character represents 6 bits
26
+ byte = (byte << 6) | map[data.charCodeAt(i)];
27
+ // each byte needs to contain 8 bits
28
+ if ((bits += 6) >= 8) {
29
+ out[++pos] = (byte >>> (bits -= 8)) & 0xff;
30
+ }
31
+ }
32
+ return out;
33
+ }
@@ -0,0 +1,3 @@
1
+ export { base64Decode } from './base64.js';
2
+ export { unzlibSync } from './fflate.js';
3
+ export { packageInfo } from './packageInfo.js';
package/cjs/bundle.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = exports.unzlibSync = exports.base64Decode = void 0;
4
+ var base64_js_1 = require("./base64.js");
5
+ Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64_js_1.base64Decode; } });
6
+ var fflate_js_1 = require("./fflate.js");
7
+ Object.defineProperty(exports, "unzlibSync", { enumerable: true, get: function () { return fflate_js_1.unzlibSync; } });
8
+ var packageInfo_js_1 = require("./packageInfo.js");
9
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
@@ -4,4 +4,4 @@
4
4
  * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
5
5
  * @returns The decompressed version of the data
6
6
  */
7
- export declare function unzlibSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
7
+ export declare function unzlibSync(data: Uint8Array, out?: Uint8Array): Uint8Array<ArrayBufferLike>;
package/cjs/fflate.js ADDED
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unzlibSync = unzlibSync;
4
+ const u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;
5
+ const clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
6
+ 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]);
7
+ 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]);
8
+ const freb = (eb, start) => {
9
+ const b = new u16(31);
10
+ for (let i = 0; i < 31; ++i) {
11
+ b[i] = start += 1 << eb[i - 1];
12
+ }
13
+ // numbers here are at max 18 bits
14
+ const r = new u32(b[30]);
15
+ for (let i = 1; i < 30; ++i) {
16
+ for (let j = b[i]; j < b[i + 1]; ++j) {
17
+ r[j] = ((j - b[i]) << 5) | i;
18
+ }
19
+ }
20
+ return [b, r];
21
+ };
22
+ const [fl, revfl] = freb(fleb, 2);
23
+ fl[28] = 258, revfl[258] = 28;
24
+ const [fd] = freb(fdeb, 0);
25
+ const rev = new u16(32768);
26
+ for (let i = 0; i < 32768; ++i) {
27
+ // reverse table algorithm from SO
28
+ let x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);
29
+ x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);
30
+ x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);
31
+ rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;
32
+ }
33
+ const hMap = ((cd, mb, r) => {
34
+ const s = cd.length;
35
+ // index
36
+ let i = 0;
37
+ // u16 "map": index -> # of codes with bit length = index
38
+ const l = new u16(mb);
39
+ // length of cd must be 288 (total # of codes)
40
+ for (; i < s; ++i) {
41
+ if (cd[i])
42
+ ++l[cd[i] - 1];
43
+ }
44
+ // u16 "map": index -> minimum code for bit length = index
45
+ const le = new u16(mb);
46
+ for (i = 1; i < mb; ++i) {
47
+ le[i] = (le[i - 1] + l[i - 1]) << 1;
48
+ }
49
+ let co;
50
+ if (r) {
51
+ // u16 "map": index -> number of actual bits, symbol for code
52
+ co = new u16(1 << mb);
53
+ // bits to remove for reverser
54
+ const rvb = 15 - mb;
55
+ for (i = 0; i < s; ++i) {
56
+ // ignore 0 lengths
57
+ if (cd[i]) {
58
+ // num encoding both symbol and bits read
59
+ const sv = (i << 4) | cd[i];
60
+ // free bits
61
+ const r = mb - cd[i];
62
+ // start value
63
+ let v = le[cd[i] - 1]++ << r;
64
+ // m is end value
65
+ for (const m = v | ((1 << r) - 1); v <= m; ++v) {
66
+ // every 16 bit value starting with the code yields the same result
67
+ co[rev[v] >> rvb] = sv;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ else {
73
+ co = new u16(s);
74
+ for (i = 0; i < s; ++i) {
75
+ if (cd[i]) {
76
+ co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
77
+ }
78
+ }
79
+ }
80
+ return co;
81
+ });
82
+ const flt = new u8(288);
83
+ for (let i = 0; i < 144; ++i)
84
+ flt[i] = 8;
85
+ for (let i = 144; i < 256; ++i)
86
+ flt[i] = 9;
87
+ for (let i = 256; i < 280; ++i)
88
+ flt[i] = 7;
89
+ for (let i = 280; i < 288; ++i)
90
+ flt[i] = 8;
91
+ const fdt = new u8(32);
92
+ for (let i = 0; i < 32; ++i)
93
+ fdt[i] = 5;
94
+ const flrm = hMap(flt, 9, 1);
95
+ const fdrm = hMap(fdt, 5, 1);
96
+ const bits = (d, p, m) => {
97
+ const o = p >>> 3;
98
+ return ((d[o] | (d[o + 1] << 8)) >>> (p & 7)) & m;
99
+ };
100
+ const bits16 = (d, p) => {
101
+ const o = p >>> 3;
102
+ return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >>> (p & 7));
103
+ };
104
+ const shft = (p) => (p >>> 3) + (p & 7 && 1);
105
+ const slc = (v, s, e) => {
106
+ if (s == null || s < 0)
107
+ s = 0;
108
+ if (e == null || e > v.length)
109
+ e = v.length;
110
+ // can't use .constructor in case user-supplied
111
+ const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s);
112
+ n.set(v.subarray(s, e));
113
+ return n;
114
+ };
115
+ const max = (a) => {
116
+ let m = a[0];
117
+ for (let i = 1, count = a.length; i < count; ++i) {
118
+ if (a[i] > m)
119
+ m = a[i];
120
+ }
121
+ return m;
122
+ };
123
+ const inflt = (dat, buf, st) => {
124
+ const noSt = !st || st.i;
125
+ if (!st)
126
+ st = {};
127
+ // source length
128
+ const sl = dat.length;
129
+ // have to estimate size
130
+ const noBuf = !buf || !noSt;
131
+ // Assumes roughly 33% compression ratio average
132
+ if (!buf)
133
+ buf = new u8(sl * 3);
134
+ // ensure buffer can fit at least l elements
135
+ const cbuf = (l) => {
136
+ let bl = buf.length;
137
+ // need to increase size to fit
138
+ if (l > bl) {
139
+ // Double or set to necessary, whichever is greater
140
+ const nbuf = new u8(Math.max(bl << 1, l));
141
+ nbuf.set(buf);
142
+ buf = nbuf;
143
+ }
144
+ };
145
+ // last chunk bitpos bytes
146
+ 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;
147
+ if (final && !lm)
148
+ return buf;
149
+ // total bits
150
+ const tbts = sl << 3;
151
+ do {
152
+ if (!lm) {
153
+ // BFINAL - this is only 1 when last chunk is next
154
+ st.f = final = bits(dat, pos, 1);
155
+ // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
156
+ const type = bits(dat, pos + 1, 3);
157
+ pos += 3;
158
+ if (!type) {
159
+ // go to end of byte boundary
160
+ const s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
161
+ if (t > sl) {
162
+ if (noSt)
163
+ throw 'unexpected EOF';
164
+ break;
165
+ }
166
+ // ensure size
167
+ if (noBuf)
168
+ cbuf(bt + l);
169
+ // Copy over uncompressed data
170
+ buf.set(dat.subarray(s, t), bt);
171
+ // Get new bitpos, update byte count
172
+ st.b = bt += l, st.p = pos = t << 3;
173
+ continue;
174
+ }
175
+ else if (type == 1)
176
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
177
+ else if (type == 2) {
178
+ // literal lengths
179
+ const hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
180
+ const tl = hLit + bits(dat, pos + 5, 31) + 1;
181
+ pos += 14;
182
+ // length+distance tree
183
+ const ldt = new u8(tl);
184
+ // code length tree
185
+ const clt = new u8(19);
186
+ for (let i = 0; i < hcLen; ++i) {
187
+ // use index map to get real code
188
+ clt[clim[i]] = bits(dat, pos + i * 3, 7);
189
+ }
190
+ pos += hcLen * 3;
191
+ // code lengths bits
192
+ const clb = max(clt), clbmsk = (1 << clb) - 1;
193
+ if (!noSt && pos + tl * (clb + 7) > tbts)
194
+ break;
195
+ // code lengths map
196
+ const clm = hMap(clt, clb, 1);
197
+ for (let i = 0; i < tl;) {
198
+ const r = clm[bits(dat, pos, clbmsk)];
199
+ // bits read
200
+ pos += r & 15;
201
+ // symbol
202
+ const s = r >>> 4;
203
+ // code length to copy
204
+ if (s < 16) {
205
+ ldt[i++] = s;
206
+ }
207
+ else {
208
+ // copy count
209
+ let c = 0, n = 0;
210
+ if (s == 16)
211
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
212
+ else if (s == 17)
213
+ n = 3 + bits(dat, pos, 7), pos += 3;
214
+ else if (s == 18)
215
+ n = 11 + bits(dat, pos, 127), pos += 7;
216
+ while (n--)
217
+ ldt[i++] = c;
218
+ }
219
+ }
220
+ // length tree distance tree
221
+ const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
222
+ // max length bits
223
+ lbt = max(lt);
224
+ // max dist bits
225
+ dbt = max(dt);
226
+ lm = hMap(lt, lbt, 1);
227
+ dm = hMap(dt, dbt, 1);
228
+ }
229
+ else
230
+ throw 'invalid block type';
231
+ if (pos > tbts)
232
+ throw 'unexpected EOF';
233
+ }
234
+ // Make sure the buffer can hold this + the largest possible addition
235
+ // maximum chunk size (practically, theoretically infinite) is 2^17;
236
+ if (noBuf)
237
+ cbuf(bt + 131072);
238
+ const lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
239
+ const mxa = lbt + dbt + 18;
240
+ while (noSt || pos + mxa < tbts) {
241
+ // bits read, code
242
+ const c = lm[bits16(dat, pos) & lms], sym = c >>> 4;
243
+ pos += c & 15;
244
+ if (pos > tbts)
245
+ throw 'unexpected EOF';
246
+ if (!c)
247
+ throw 'invalid length/literal';
248
+ if (sym < 256)
249
+ buf[bt++] = sym;
250
+ else if (sym == 256) {
251
+ lm = undefined;
252
+ break;
253
+ }
254
+ else {
255
+ let add = sym - 254;
256
+ // no extra bits needed if less
257
+ if (sym > 264) {
258
+ // index
259
+ const i = sym - 257, b = fleb[i];
260
+ add = bits(dat, pos, (1 << b) - 1) + fl[i];
261
+ pos += b;
262
+ }
263
+ // dist
264
+ const d = dm[bits16(dat, pos) & dms], dsym = d >>> 4;
265
+ if (!d)
266
+ throw 'invalid distance';
267
+ pos += d & 15;
268
+ let dt = fd[dsym];
269
+ if (dsym > 3) {
270
+ const b = fdeb[dsym];
271
+ dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;
272
+ }
273
+ if (pos > tbts)
274
+ throw 'unexpected EOF';
275
+ if (noBuf)
276
+ cbuf(bt + 131072);
277
+ const end = bt + add;
278
+ for (; bt < end; bt += 4) {
279
+ buf[bt] = buf[bt - dt];
280
+ buf[bt + 1] = buf[bt + 1 - dt];
281
+ buf[bt + 2] = buf[bt + 2 - dt];
282
+ buf[bt + 3] = buf[bt + 3 - dt];
283
+ }
284
+ bt = end;
285
+ }
286
+ }
287
+ st.l = lm, st.p = pos, st.b = bt;
288
+ if (lm)
289
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
290
+ } while (!final);
291
+ return bt == buf.length ? buf : slc(buf, 0, bt);
292
+ };
293
+ const zlv = (d) => {
294
+ if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31))
295
+ throw 'invalid zlib data';
296
+ if (d[1] & 32)
297
+ throw 'invalid zlib data: preset dictionaries not supported';
298
+ };
299
+ /**
300
+ * Expands Zlib data
301
+ * @param data The data to decompress
302
+ * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
303
+ * @returns The decompressed version of the data
304
+ */
305
+ function unzlibSync(data, out) {
306
+ return inflt((zlv(data), data.subarray(2, -4)), out);
307
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("./packageDetect.js");
5
+ tslib_1.__exportStar(require("./bundle.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("@pezkuwi/util");
4
+ const packageInfo_js_1 = require("./packageInfo.js");
5
+ (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, []);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = void 0;
4
+ exports.packageInfo = { name: '@pezkuwi/wasm-util', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '7.5.10' };
package/fflate.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Expands Zlib data
3
+ * @param data The data to decompress
4
+ * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
5
+ * @returns The decompressed version of the data
6
+ */
7
+ export declare function unzlibSync(data: Uint8Array, out?: Uint8Array): Uint8Array<ArrayBufferLike>;