@zip.js/zip.js 2.8.30 → 2.8.31
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/deno.json +5 -4
- package/dist/zip-core.js +133 -334
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +115 -277
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +170 -373
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +169 -372
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +138 -339
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-module.wasm +0 -0
- package/dist/zip-native.js +141 -342
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +140 -341
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +170 -373
- package/index-native.min.js +1 -1
- package/index.cjs +169 -372
- package/index.d.cts +2814 -0
- package/index.d.ts +238 -0
- package/index.min.js +1 -1
- package/lib/core/codec-worker.js +0 -10
- package/lib/core/configuration.js +21 -33
- package/lib/core/constants.js +3 -0
- package/lib/core/io.js +11 -19
- package/lib/core/streams/aes-crypto-stream.js +16 -20
- package/lib/core/streams/common-crypto.js +0 -2
- package/lib/core/streams/zip-crypto-stream.js +12 -16
- package/lib/core/streams/zip-entry-stream.js +2 -32
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/streams/zlib-wasm/zlib-streams-loader.js +1 -3
- package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
- package/lib/core/util/base64.js +68 -0
- package/lib/core/util/decode-text.js +0 -1
- package/lib/core/util/default-mime-type.js +0 -3
- package/lib/core/util/inflate.js +194 -0
- package/lib/core/util/mime-type.js +26 -22
- package/lib/core/util/opfs-temp-stream.js +1 -37
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-template-native.js +5 -5
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +6 -13
- package/lib/core/zip-reader.js +48 -127
- package/lib/core/zip-writer.js +27 -45
- package/lib/core/zlib-streams-inline-template.js +3 -2
- package/lib/core/zlib-streams-inline.js +1 -1
- package/lib/zip-core-base.js +3 -1
- package/package.json +9 -6
- package/reserved-property-names.js +50 -0
- package/lib/core/util/mini-lz.js +0 -198
package/lib/core/util/mini-lz.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
this list of conditions and the following disclaimer.
|
|
9
|
-
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in
|
|
12
|
-
the documentation and/or other materials provided with the distribution.
|
|
13
|
-
|
|
14
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
18
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
20
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
22
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
23
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
26
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
30
|
-
|
|
31
|
-
export function base64Decode(b64) {
|
|
32
|
-
b64 = String(b64).replace(/[^A-Za-z0-9+/=]/g, "");
|
|
33
|
-
const len = b64.length;
|
|
34
|
-
const out = [];
|
|
35
|
-
for (let i = 0; i < len; i += 4) {
|
|
36
|
-
const a = BASE64_TABLE.indexOf(b64[i]);
|
|
37
|
-
const b = BASE64_TABLE.indexOf(b64[i + 1]);
|
|
38
|
-
const c = BASE64_TABLE.indexOf(b64[i + 2]);
|
|
39
|
-
const d = BASE64_TABLE.indexOf(b64[i + 3]);
|
|
40
|
-
const n = (a << 18) | (b << 12) | ((c & 63) << 6) | (d & 63);
|
|
41
|
-
out.push((n >> 16) & 0xff);
|
|
42
|
-
if (b64[i + 2] !== "=") {
|
|
43
|
-
out.push((n >> 8) & 0xff);
|
|
44
|
-
}
|
|
45
|
-
if (b64[i + 3] !== "=") {
|
|
46
|
-
out.push(n & 0xff);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return new Uint8Array(out);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function base64Encode(bytes) {
|
|
53
|
-
let out = "";
|
|
54
|
-
const len = bytes.length;
|
|
55
|
-
let i = 0;
|
|
56
|
-
for (; i + 2 < len; i += 3) {
|
|
57
|
-
const n = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
|
58
|
-
out += BASE64_TABLE[(n >> 18) & 63] + BASE64_TABLE[(n >> 12) & 63] + BASE64_TABLE[(n >> 6) & 63] + BASE64_TABLE[n & 63];
|
|
59
|
-
}
|
|
60
|
-
const rem = len - i;
|
|
61
|
-
if (rem === 1) {
|
|
62
|
-
const n = bytes[i] << 16;
|
|
63
|
-
out += BASE64_TABLE[(n >> 18) & 63] + BASE64_TABLE[(n >> 12) & 63] + "==";
|
|
64
|
-
} else if (rem === 2) {
|
|
65
|
-
const n = (bytes[i] << 16) | (bytes[i + 1] << 8);
|
|
66
|
-
out += BASE64_TABLE[(n >> 18) & 63] + BASE64_TABLE[(n >> 12) & 63] + BASE64_TABLE[(n >> 6) & 63] + "=";
|
|
67
|
-
}
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function decompress(src) {
|
|
72
|
-
src = base64Decode(src);
|
|
73
|
-
let out = new Uint8Array(1024);
|
|
74
|
-
let outLen = 0;
|
|
75
|
-
for (let i = 0; i < src.length;) {
|
|
76
|
-
const ctrl = src[i++];
|
|
77
|
-
if ((ctrl & 0x80) === 0) {
|
|
78
|
-
const L = ctrl;
|
|
79
|
-
ensure(outLen + L);
|
|
80
|
-
for (let j = 0; j < L && i < src.length; j++) {
|
|
81
|
-
out[outLen++] = src[i++];
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
const L = (ctrl & 0x7f) + 3;
|
|
85
|
-
const off = (src[i++] << 8) | src[i++];
|
|
86
|
-
const start = outLen - off;
|
|
87
|
-
ensure(outLen + L);
|
|
88
|
-
for (let k = 0; k < L; k++) {
|
|
89
|
-
out[outLen++] = out[start + k];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const data = new Uint8Array(out.buffer.slice(0, outLen));
|
|
94
|
-
return base64Encode(data);
|
|
95
|
-
|
|
96
|
-
function ensure(n) {
|
|
97
|
-
if (out.length < n) {
|
|
98
|
-
let nl = out.length * 2;
|
|
99
|
-
while (nl < n) {
|
|
100
|
-
nl *= 2;
|
|
101
|
-
}
|
|
102
|
-
const nbuf = new Uint8Array(nl);
|
|
103
|
-
nbuf.set(out.subarray(0, outLen));
|
|
104
|
-
out = nbuf;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function compress(input) {
|
|
110
|
-
const src = new Uint8Array(input);
|
|
111
|
-
const N = src.length;
|
|
112
|
-
const out = [];
|
|
113
|
-
const litBuf = [];
|
|
114
|
-
const MAX_OFFSET = 0xffff;
|
|
115
|
-
const MAX_MATCH = 130;
|
|
116
|
-
const MAX_CANDIDATES = 64;
|
|
117
|
-
const map = new Map();
|
|
118
|
-
let i = 0;
|
|
119
|
-
while (i < N) {
|
|
120
|
-
let bestLen = 0, bestOff = 0;
|
|
121
|
-
if (i + 2 < N) {
|
|
122
|
-
const key = (src[i] << 16) | (src[i + 1] << 8) | src[i + 2];
|
|
123
|
-
const cand = map.get(key) || [];
|
|
124
|
-
for (let c = cand.length - 1; c >= 0; c--) {
|
|
125
|
-
const j = cand[c];
|
|
126
|
-
const off = i - j;
|
|
127
|
-
if (off <= 0 || off > MAX_OFFSET) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
let k = 0;
|
|
131
|
-
while (k < MAX_MATCH && i + k < N && src[j + k] === src[i + k]) {
|
|
132
|
-
k++;
|
|
133
|
-
}
|
|
134
|
-
if (k > bestLen && k >= 3) {
|
|
135
|
-
bestLen = k; bestOff = off;
|
|
136
|
-
if (bestLen === MAX_MATCH) {
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (bestLen >= 3) {
|
|
144
|
-
if (litBuf.length) {
|
|
145
|
-
flushLiterals();
|
|
146
|
-
}
|
|
147
|
-
let remain = bestLen;
|
|
148
|
-
let produced = 0;
|
|
149
|
-
while (remain > 0) {
|
|
150
|
-
const take = Math.min(remain, MAX_MATCH);
|
|
151
|
-
out.push(0x80 | ((take - 3) & 0x7f));
|
|
152
|
-
out.push((bestOff >> 8) & 0xff);
|
|
153
|
-
out.push(bestOff & 0xff);
|
|
154
|
-
remain -= take;
|
|
155
|
-
produced += take;
|
|
156
|
-
}
|
|
157
|
-
const start = i;
|
|
158
|
-
for (let p = start; p < start + produced; p++) {
|
|
159
|
-
addPos(p);
|
|
160
|
-
}
|
|
161
|
-
i += produced;
|
|
162
|
-
} else {
|
|
163
|
-
litBuf.push(src[i]);
|
|
164
|
-
addPos(i);
|
|
165
|
-
i++;
|
|
166
|
-
if (litBuf.length === 127) {
|
|
167
|
-
flushLiterals();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (litBuf.length) {
|
|
172
|
-
flushLiterals();
|
|
173
|
-
}
|
|
174
|
-
const u8 = new Uint8Array(out);
|
|
175
|
-
return base64Encode(u8);
|
|
176
|
-
|
|
177
|
-
function flushLiterals() {
|
|
178
|
-
while (litBuf.length) {
|
|
179
|
-
const take = Math.min(127, litBuf.length);
|
|
180
|
-
out.push(take);
|
|
181
|
-
for (let t = 0; t < take; t++) {
|
|
182
|
-
out.push(litBuf.shift());
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function addPos(pos) {
|
|
188
|
-
if (pos + 2 < N) {
|
|
189
|
-
const key = (src[pos] << 16) | (src[pos + 1] << 8) | src[pos + 2];
|
|
190
|
-
const arr = map.get(key) || [];
|
|
191
|
-
arr.push(pos);
|
|
192
|
-
if (arr.length > MAX_CANDIDATES) {
|
|
193
|
-
arr.shift();
|
|
194
|
-
}
|
|
195
|
-
map.set(key, arr);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|