@zip.js/zip.js 2.7.72 → 2.8.0
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 +2 -3
- package/dist/README.md +7 -25
- package/dist/zip-core.js +5961 -0
- package/dist/zip-core.min.js +1 -0
- package/dist/{zip-full.js → zip-fs-core.js} +4161 -7360
- package/dist/zip-fs-core.min.js +1 -0
- package/dist/zip-fs.js +4357 -2545
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-module.wasm +0 -0
- package/dist/zip-web-worker.js +1 -0
- package/dist/zip.js +2648 -2468
- package/dist/zip.min.js +1 -1
- package/index.cjs +4625 -8661
- package/index.d.ts +29 -178
- package/index.js +2 -63
- package/index.min.js +1 -1
- package/lib/core/codec-pool.js +6 -4
- package/lib/core/codec-worker.js +37 -20
- package/lib/core/configuration.js +16 -37
- package/lib/core/io.js +3 -8
- package/lib/core/streams/aes-crypto-stream.js +1 -0
- package/lib/core/streams/zip-crypto-stream.js +1 -1
- package/lib/core/streams/zip-entry-stream.js +19 -12
- package/lib/core/streams/zlib/README.md +1 -0
- package/lib/core/streams/{stream-adapter.js → zlib/zlib-streams-loader.js} +54 -25
- package/lib/core/streams/zlib/zlib-streams.js +184 -0
- package/lib/core/streams/zlib/zlib-streams.wasm +0 -0
- package/lib/core/util/decode-text.js +1 -1
- package/lib/core/util/encode-text.js +1 -0
- package/lib/core/util/mini-lz.js +198 -0
- package/lib/{z-worker.js → core/web-worker-inline-template.js} +10 -9
- package/lib/core/web-worker-inline.js +1 -0
- package/lib/core/{z-worker-core.js → web-worker.js} +17 -36
- package/lib/core/zip-entry.js +3 -7
- package/lib/core/zip-reader.js +12 -5
- package/lib/core/zip-writer.js +11 -13
- package/lib/{z-worker-bootstrap-pako.js → core/zlib-streams-inline-template.js} +8 -10
- package/lib/core/zlib-streams-inline.js +1 -0
- package/{index-fflate.js → lib/zip-core.js} +43 -22
- package/lib/{z-worker-fflate.js → zip-fs-core.js} +5 -15
- package/lib/zip-fs.js +7 -24
- package/lib/zip.js +6 -23
- package/package.json +7 -21
- package/dist/z-worker-fflate.js +0 -1
- package/dist/z-worker-pako.js +0 -1
- package/dist/z-worker.js +0 -1
- package/dist/zip-fs-full.js +0 -12537
- package/dist/zip-fs-full.min.js +0 -1
- package/dist/zip-full.min.js +0 -1
- package/dist/zip-no-worker-deflate.min.js +0 -1
- package/dist/zip-no-worker-inflate.min.js +0 -1
- package/dist/zip-no-worker.min.js +0 -1
- package/lib/core/streams/codecs/deflate.js +0 -2059
- package/lib/core/streams/codecs/inflate.js +0 -2163
- package/lib/core/util/stream-codec-shim.js +0 -91
- package/lib/z-worker-bootstrap-fflate.js +0 -40
- package/lib/z-worker-inline-template.js +0 -42
- package/lib/z-worker-inline.js +0 -1
- package/lib/zip-data-uri.js +0 -56
- package/lib/zip-fflate-shim.js +0 -37
- package/lib/zip-full-fflate.js +0 -54
- package/lib/zip-full.js +0 -55
- package/lib/zip-no-worker-deflate.js +0 -42
- package/lib/zip-no-worker-fflate-deflate.js +0 -42
- package/lib/zip-no-worker-fflate-inflate.js +0 -42
- package/lib/zip-no-worker-fflate.js +0 -43
- package/lib/zip-no-worker-inflate.js +0 -42
- package/lib/zip-no-worker.js +0 -44
- /package/lib/core/util/{cp437-decode.js → decode-cp437.js} +0 -0
- /package/lib/core/{zip-fs-core.js → zip-fs.js} +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/*
|
|
29
|
+
/* eslint-disable quotes */
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
export {
|
|
32
|
+
configureWebWorker
|
|
33
|
+
};
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
35
|
+
function configureWebWorker(configure) {
|
|
36
|
+
const code = `__workerCode__`;
|
|
37
|
+
const uri = () => "data:text/javascript," + encodeURIComponent(code);
|
|
38
|
+
configure({ workerURI: uri });
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){t({workerURI:()=>"data:text/javascript,"+encodeURIComponent('(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:i,Uint32Array:c,Int32Array:a,Map:h,DataView:l,Promise:u,TextEncoder:f,crypto:w,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:g,DecompressionStream:b}=self,S=[];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)1&e?e=e>>>1^3988292384:e>>>=1;S[t]=e}class v{constructor(t){this.t=t||-1}append(t){let e=0|this.t;for(let n=0,s=0|t.length;s>n;n++)e=e>>>8^S[255&(e^t[n])];this.t=e}get(){return~this.t}}class k extends d{constructor(){let t;const e=new v;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}const z="undefined",C="function",A={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=A.o(n);return 32===s?t.concat(e):A.i(e,s,0|n,t.slice(0,t.length-1))},h(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+A.o(n)},l(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=A.u(e,t[n-1]&2147483648>>e-1,1)),t},u:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,o:t=>s.round(t/1099511627776)||32,i(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=A.o(r);return s.push(A.u(e+o&31,e+o>32?n:s.pop(),1)),s}},x={bytes:{p(t){const e=A.h(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},m(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(A.u(8*(3&n),s)),e}}},I=class{constructor(t){const e=this;e.blockSize=512,e.S=[1732584193,4023233417,2562383102,271733878,3285377520],e.v=[1518500249,1859775393,2400959708,3395469782],t?(e.k=t.k.slice(0),e.C=t.C.slice(0),e.A=t.A):e.reset()}reset(){const t=this;return t.k=t.S.slice(0),t.C=[],t.A=0,t}update(t){const e=this;"string"==typeof t&&(t=x.I.m(t));const n=e.C=A.concat(e.C,t),s=e.A,o=e.A=s+A.h(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const i=new c(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.R(i.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}P(){const t=this;let e=t.C;const n=t.k;e=A.concat(e,[A.u(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.A/4294967296)),e.push(0|t.A);e.length;)t.R(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}V(t,e){return e<<t|e>>>32-t}R(e){const n=this,r=n.k,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let i=r[0],c=r[1],a=r[2],h=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.V(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.V(5,i)+n.U(t,c,a,h)+l+o[t]+n.v[s.floor(t/20)]|0;l=h,h=a,a=n.V(30,c),c=i,i=e}r[0]=r[0]+i|0,r[1]=r[1]+c|0,r[2]=r[2]+a|0,r[3]=r[3]+h|0,r[4]=r[4]+l|0}},R={getRandomValues(t){const e=new c(t.buffer),n=t=>{let e=987654321;const n=4294967295;return()=>(e=36969*(65535&e)+(e>>16)&n,(((e<<16)+(t=18e3*(65535&t)+(t>>16)&n)&n)/4294967296+.5)*(s.random()>.5?1:-1))};for(let r,o=0;o<t.length;o+=4){const t=n(4294967296*(r||s.random()));r=987654071*t(),e[o/4]=4294967296*t()|0}return t}},P={importKey:t=>new P._(x.bytes.m(t)),B(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let i,c,a,h,u;const f=new ArrayBuffer(o),w=new l(f);let p=0;const d=A;for(e=x.bytes.m(e),u=1;(o||1)>p;u++){for(i=c=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(c=t.encrypt(c),h=0;h<c.length;h++)i[h]^=c[h];for(a=0;(o||1)>p&&a<i.length;a++)w.setInt32(p,i[a]),p+=4}return f.slice(0,s/8)},_:class{constructor(t){const e=this,n=e.D=I,s=[[],[]];e.M=[new n,new n];const r=e.M[0].blockSize/32;t.length>r&&(t=(new n).update(t).P());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.M[0].update(s[0]),e.M[1].update(s[1]),e.K=new n(e.M[0])}reset(){const t=this;t.K=new t.D(t.M[0]),t.W=!1}update(t){this.W=!0,this.K.update(t)}digest(){const t=this,e=t.K.P(),n=new t.D(t.M[1]).update(e).P();return t.reset(),n}encrypt(t){if(this.W)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},U=typeof w!=z&&typeof w.getRandomValues==C,V="Invalid password",_="Invalid signature",B="zipjs-abort-check-password";function D(t){return U?w.getRandomValues(t):R.getRandomValues(t)}const M=16,K={name:"PBKDF2"},W=e.assign({hash:{name:"HMAC"}},K),E=e.assign({iterations:1e3,hash:{name:"SHA-1"}},K),L=["deriveBits"],O=[8,12,16],T=[16,24,32],j=10,H=[0,0,0,0],Z=typeof w!=z,F=Z&&w.subtle,N=Z&&typeof F!=z,q=x.bytes,G=class{constructor(t){const e=this;e.L=[[[],[],[],[],[]],[[],[],[],[],[]]],e.L[0][0][0]||e.O();const n=e.L[0][4],s=e.L[1],o=t.length;let i,c,a,h=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.v=[c=t.slice(0),a=[]],i=o;4*o+28>i;i++){let t=c[i-1];(i%o===0||8===o&&i%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],i%o===0&&(t=t<<8^t>>>24^h<<24,h=h<<1^283*(h>>7))),c[i]=c[i-o]^t}for(let t=0;i;t++,i--){const e=c[3&t?i:i-4];a[t]=4>=i||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.T(t,0)}decrypt(t){return this.T(t,1)}O(){const t=this.L[0],e=this.L[1],n=t[4],s=e[4],r=[],o=[];let i,c,a,h;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=i=0;!n[l];l^=c||1,i=o[i]||1){let o=i^i<<1^i<<2^i<<3^i<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,h=r[a=r[c=r[l]]];let u=16843009*h^65537*a^257*c^16843008*l,f=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=f=f<<24^f>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}T(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.v[e],s=n.length/4-2,o=[0,0,0,0],i=this.L[e],c=i[0],a=i[1],h=i[2],l=i[3],u=i[4];let f,w,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],g=t[e?1:3]^n[3],b=4;for(let t=0;s>t;t++)f=c[d>>>24]^a[y>>16&255]^h[m>>8&255]^l[255&g]^n[b],w=c[y>>>24]^a[m>>16&255]^h[g>>8&255]^l[255&d]^n[b+1],p=c[m>>>24]^a[g>>16&255]^h[d>>8&255]^l[255&y]^n[b+2],g=c[g>>>24]^a[d>>16&255]^h[y>>8&255]^l[255&m]^n[b+3],b+=4,d=f,y=w,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&g]^n[b++],f=d,d=y,y=m,m=g,g=f;return o}},J=class{constructor(t,e){this.j=t,this.H=e,this.Z=e}reset(){this.Z=this.H}update(t){return this.F(this.j,t,this.Z)}N(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}q(t){0===(t[0]=this.N(t[0]))&&(t[1]=this.N(t[1]))}F(t,e,n){let s;if(!(s=e.length))return[];const r=A.h(e);for(let r=0;s>r;r+=4){this.q(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return A.l(e,r)}},Q=P._;let X=Z&&N&&typeof F.importKey==C,Y=Z&&N&&typeof F.deriveBits==C;class $ extends d{constructor({password:t,rawPassword:n,signed:s,encryptionStrength:i,checkPasswordOnly:c}){super({start(){e.assign(this,{ready:new u(t=>this.G=t),password:st(t,n),signed:s,J:i-1,pending:new o})},async transform(t,e){const n=this,{password:s,J:i,G:a,ready:h}=n;s?(await(async(t,e,n,s)=>{const o=await nt(t,e,n,ot(s,0,O[e])),i=ot(s,O[e]);if(o[0]!=i[0]||o[1]!=i[1])throw new r(V)})(n,i,s,ot(t,0,O[i]+2)),t=ot(t,O[i]+2),c?e.error(new r(B)):a()):await h;const l=new o(t.length-j-(t.length-j)%M);e.enqueue(et(n,t,l,0,j,!0))},async flush(t){const{signed:e,X:n,Y:s,pending:i,ready:c}=this;if(s&&n){await c;const a=ot(i,0,i.length-j),h=ot(i,i.length-j);let l=new o;if(a.length){const t=ct(q,a);s.update(t);const e=n.update(t);l=it(q,e)}if(e){const t=ot(it(q,s.digest()),0,j);for(let e=0;j>e;e++)if(t[e]!=h[e])throw new r(_)}t.enqueue(l)}}})}}class tt extends d{constructor({password:t,rawPassword:n,encryptionStrength:s}){let r;super({start(){e.assign(this,{ready:new u(t=>this.G=t),password:st(t,n),J:s-1,pending:new o})},async transform(t,e){const n=this,{password:s,J:r,G:i,ready:c}=n;let a=new o;s?(a=await(async(t,e,n)=>{const s=D(new o(O[e]));return rt(s,await nt(t,e,n,s))})(n,r,s),i()):await c;const h=new o(a.length+t.length-t.length%M);h.set(a,0),e.enqueue(et(n,t,h,a.length,0))},async flush(t){const{X:e,Y:n,pending:s,ready:i}=this;if(n&&e){await i;let c=new o;if(s.length){const t=e.update(ct(q,s));n.update(t),c=it(q,t)}r.signature=it(q,n.digest()).slice(0,j),t.enqueue(rt(c,r.signature))}}}),r=this}}function et(t,e,n,s,r,i){const{X:c,Y:a,pending:h}=t,l=e.length-r;let u;for(h.length&&(e=rt(h,e),n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,l-l%M)),u=0;l-M>=u;u+=M){const t=ct(q,ot(e,u,u+M));i&&a.update(t);const r=c.update(t);i||a.update(r),n.set(it(q,r),u+s)}return t.pending=ot(e,u),n}async function nt(n,s,r,i){n.password=null;const c=await(async(t,e,n,s,r)=>{if(!X)return P.importKey(e);try{return await F.importKey("raw",e,n,!1,r)}catch(t){return X=!1,P.importKey(e)}})(0,r,W,0,L),a=await(async(t,e,n)=>{if(!Y)return P.B(e,t.salt,E.iterations,n);try{return await F.deriveBits(t,e,n)}catch(s){return Y=!1,P.B(e,t.salt,E.iterations,n)}})(e.assign({salt:i},E),c,8*(2*T[s]+2)),h=new o(a),l=ct(q,ot(h,0,T[s])),u=ct(q,ot(h,T[s],2*T[s])),f=ot(h,2*T[s]);return e.assign(n,{keys:{key:l,$:u,passwordVerification:f},X:new J(new G(l),t.from(H)),Y:new Q(u)}),f}function st(t,e){return void 0===e?(t=>{if(typeof f==z){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new f).encode(t)})(t):e}function rt(t,e){let n=t;return t.length+e.length&&(n=new o(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function ot(t,e,n){return t.subarray(e,n)}function it(t,e){return t.p(e)}function ct(t,e){return t.m(e)}class at extends d{constructor({password:t,passwordVerification:n,checkPasswordOnly:s}){super({start(){e.assign(this,{password:t,passwordVerification:n}),ft(this,t)},transform(t,e){const n=this;if(n.password){const e=lt(n,t.subarray(0,12));if(n.password=null,e.at(-1)!=n.passwordVerification)throw new r(V);t=t.subarray(12)}s?e.error(new r(B)):e.enqueue(lt(n,t))}})}}class ht extends d{constructor({password:t,passwordVerification:n}){super({start(){e.assign(this,{password:t,passwordVerification:n}),ft(this,t)},transform(t,e){const n=this;let s,r;if(n.password){n.password=null;const e=D(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(ut(n,e),0),r=12}else s=new o(t.length),r=0;s.set(ut(n,t),r),e.enqueue(s)}})}}function lt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=pt(t)^e[s],wt(t,n[s]);return n}function ut(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=pt(t)^e[s],wt(t,e[s]);return n}function ft(t,n){const s=[305419896,591751049,878082192];e.assign(t,{keys:s,tt:new v(s[0]),et:new v(s[2])});for(let e=0;e<n.length;e++)wt(t,n.charCodeAt(e))}function wt(t,e){let[n,r,o]=t.keys;t.tt.append([e]),n=~t.tt.get(),r=yt(s.imul(yt(r+dt(n)),134775813)+1),t.et.append([r>>>24]),o=~t.et.get(),t.keys=[n,r,o]}function pt(t){const e=2|t.keys[2];return dt(s.imul(e,1^e)>>>8)}function dt(t){return 255&t}function yt(t){return 4294967295&t}class mt extends d{constructor(t,{chunkSize:e,nt:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:i,zipCrypto:c,signed:a,level:h}=t,u=this;let f,w,p=super.readable;o&&!c||!a||(f=new k,p=vt(p,f)),r&&(p=St(p,i,{level:h,chunkSize:e},s,n,s)),o&&(c?p=vt(p,new ht(t)):(w=new tt(t),p=vt(p,w))),bt(u,p,()=>{let t;o&&!c&&(t=w.signature),o&&!c||!a||(t=new l(f.value.buffer).getUint32(0)),u.signature=t})}}class gt extends d{constructor(t,{chunkSize:e,st:n,DecompressionStream:s}){super({});const{zipCrypto:o,encrypted:i,signed:c,signature:a,compressed:h,useCompressionStream:u,rt:f}=t;let w,p,d=super.readable;i&&(o?d=vt(d,new at(t)):(p=new $(t),d=vt(d,p))),h&&(d=St(d,u,{chunkSize:e,rt:f},s,n,s)),i&&!o||!c||(w=new k,d=vt(d,w)),bt(this,d,()=>{if((!i||o)&&c){const t=new l(w.value.buffer);if(a!=t.getUint32(0,!1))throw new r(_)}})}}function bt(t,n,s){n=vt(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function St(t,e,n,s,r,o){const i=e&&s?s:r||o,c=n.rt?"deflate64-raw":"deflate-raw";try{t=vt(t,new i(c,n))}catch(s){if(!e)throw s;if(r)t=vt(t,new r(c,n));else{if(!o)throw s;t=vt(t,new o(c,n))}}return t}function vt(t,e){return t.pipeThrough(e)}const kt="data",zt="close";class Ct extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let i;o.startsWith("deflate")?i=mt:o.startsWith("inflate")&&(i=gt),s.outputSize=0;let c=0;const a=new i(t,n),h=super.readable,l=new d({transform(t,e){t&&t.length&&(c+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:c})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize&&s.outputSize>t.outputSize))throw new r("Invalid uncompressed size")},flush(){const{signature:t}=a;e.assign(s,{signature:t,inputSize:c})}});e.defineProperty(s,"readable",{get:()=>h.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class At extends d{constructor(t){let e;super({transform:function n(s,r){if(e){const t=new o(e.length+s.length);t.set(e),t.set(s,e.length),s=t,e=null}s.length>t?(r.enqueue(s.slice(0,t)),n(s.slice(t),r)):e=s},flush(t){e&&e.length&&t.enqueue(e)}})}}let xt,It,Rt,Pt;function Ut(t,e,n={}){const i="number"==typeof n.level?n.level:-1,c="number"==typeof n.ot?n.ot:65536,a="number"==typeof n.it?n.it:65536;return new d({start(){let n;if(this.ct=It(c),this.in=It(a),this.it=a,this.ht=new o(c),t?(this.lt=xt.deflate_process,this.ut=xt.deflate_last_consumed,this.ft=xt.deflate_end,this.wt=xt.deflate_new(),n="gzip"===e?xt.deflate_init_gzip(this.wt,i):"deflate-raw"===e?xt.deflate_init_raw(this.wt,i):xt.deflate_init(this.wt,i)):"deflate64-raw"===e?(this.lt=xt.inflate9_process,this.ut=xt.inflate9_last_consumed,this.ft=xt.inflate9_end,this.wt=xt.inflate9_new(),n=xt.inflate9_init_raw(this.wt)):(this.lt=xt.inflate_process,this.ut=xt.inflate_last_consumed,this.ft=xt.inflate_end,this.wt=xt.inflate_new(),n="deflate-raw"===e?xt.inflate_init_raw(this.wt):"gzip"===e?xt.inflate_init_gzip(this.wt):xt.inflate_init(this.wt)),0!==n)throw new r("init failed:"+n)},transform(e,n){try{const i=e,a=new o(Pt.buffer),h=this.lt,l=this.ut,u=this.ct,f=this.ht;let w=0;for(;w<i.length;){const e=s.min(i.length-w,32768);this.in&&this.it>=e||(this.in&&Rt&&Rt(this.in),this.in=It(e),this.it=e),a.set(i.subarray(w,w+e),this.in);const o=h(this.wt,this.in,e,u,c,0);if(!t&&0>o)throw new r("process error:"+o);const p=16777215&o;p&&(f.set(a.subarray(u,u+p),0),n.enqueue(f.slice(0,p)));const d=l(this.wt);if(0===d)break;w+=d}}catch(t){this.ft&&this.wt&&this.ft(this.wt),this.in&&Rt&&Rt(this.in),this.ct&&Rt&&Rt(this.ct),n.error(t)}},flush(e){try{const n=new o(Pt.buffer),s=this.lt,i=this.ct,a=this.ht;for(;;){const o=s(this.wt,0,0,i,c,4);if(!t&&0>o)throw new r("process error:"+o);const h=16777215&o,l=o>>24&255;if(h&&(a.set(n.subarray(i,i+h),0),e.enqueue(a.slice(0,h))),1===l||0===h)break}}catch(t){e.error(t)}finally{if(this.ft&&this.wt){const t=this.ft(this.wt);0!==t&&e.error(new r("end error:"+t))}this.in&&Rt&&Rt(this.in),this.ct&&Rt&&Rt(this.ct)}}})}class Vt{constructor(t="deflate",e){return Ut(!0,t,e)}}class _t{constructor(t="deflate",e){return Ut(!1,t,e)}}let Bt=!1;const Dt=new h,Mt=new h;let Kt,Wt=0;async function Et(t){try{const{options:e,config:s}=t;Bt||e.useCompressionStream||await(async(t,{baseURI:e})=>{if(!Bt){let s,r;try{try{r=new URL(t,e)}catch(t){}const n=await fetch(r);s=await n.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;s=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}n=(await WebAssembly.instantiate(s)).instance.exports,xt=n,({malloc:It,free:Rt,memory:Pt}=xt),Bt=!0}var n})(t.config.wasmURI,t.config),s.CompressionStream=self.CompressionStream,s.DecompressionStream=self.DecompressionStream,s.nt=Vt,s.st=_t;const r={highWaterMark:1},i=t.readable||new y({async pull(t){const e=new u(t=>Dt.set(Wt,t));Lt({type:"pull",messageId:Wt}),Wt=(Wt+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},r),c=t.writable||new m({async write(t){let e;const s=new u(t=>e=t);Mt.set(Wt,e),Lt({type:kt,value:t,messageId:Wt}),Wt=(Wt+1)%n.MAX_SAFE_INTEGER,await s}},r),a=new Ct(e,s);Kt=new AbortController;const{signal:h}=Kt;await i.pipeThrough(a).pipeThrough(new At(s.chunkSize)).pipeTo(c,{signal:h,preventClose:!0,preventAbort:!0}),await c.getWriter().close();const{signature:l,inputSize:f,outputSize:w}=a;Lt({type:zt,result:{signature:l,inputSize:f,outputSize:w}})}catch(t){t.outputSize=0,Ot(t)}}function Lt(t){let{value:e}=t;if(e)if(e.length)try{e=new o(e),t.value=e.buffer,p(t,[t.value])}catch(e){p(t)}else p(t);else p(t)}function Ot(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:i}=t;p({error:{message:e,stack:n,code:s,name:o,outputSize:i}})}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&Et(t),e==kt){const t=Dt.get(n);Dt.delete(n),t({value:new o(s),done:r})}if("ack"==e){const t=Mt.get(n);Mt.delete(n),t()}e==zt&&Kt.abort()}catch(t){Ot(t)}})});\n')})}export{t as configureWebWorker};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -26,10 +26,8 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global self,
|
|
29
|
+
/* global self, addEventListener, postMessage, ReadableStream, WritableStream, AbortController */
|
|
30
30
|
|
|
31
|
-
import { UNDEFINED_VALUE } from "./constants.js";
|
|
32
|
-
import { StreamAdapter } from "./streams/stream-adapter.js";
|
|
33
31
|
import {
|
|
34
32
|
CodecStream,
|
|
35
33
|
ChunkStream,
|
|
@@ -40,11 +38,17 @@ import {
|
|
|
40
38
|
MESSAGE_ACK_DATA,
|
|
41
39
|
MESSAGE_CLOSE
|
|
42
40
|
} from "./streams/codec-stream.js";
|
|
41
|
+
import {
|
|
42
|
+
CompressionStreamZlib,
|
|
43
|
+
DecompressionStreamZlib,
|
|
44
|
+
initModule,
|
|
45
|
+
initializedModule
|
|
46
|
+
} from "./streams/zlib/zlib-streams-loader.js";
|
|
43
47
|
|
|
44
48
|
const pendingPullMessages = new Map();
|
|
45
49
|
const pendingDataMessages = new Map();
|
|
46
50
|
|
|
47
|
-
let abortController, messageId = 0
|
|
51
|
+
let abortController, messageId = 0;
|
|
48
52
|
|
|
49
53
|
addEventListener(MESSAGE_EVENT_TYPE, ({ data }) => {
|
|
50
54
|
const { type, messageId, value, done } = data;
|
|
@@ -73,31 +77,14 @@ addEventListener(MESSAGE_EVENT_TYPE, ({ data }) => {
|
|
|
73
77
|
async function init(message) {
|
|
74
78
|
let codecStream;
|
|
75
79
|
try {
|
|
76
|
-
const { options,
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
if (importScriptSupported) {
|
|
80
|
-
importScripts.apply(UNDEFINED_VALUE, scripts);
|
|
81
|
-
} else {
|
|
82
|
-
await imporModuleScripts(scripts);
|
|
83
|
-
}
|
|
84
|
-
// eslint-disable-next-line no-unused-vars
|
|
85
|
-
} catch (_) {
|
|
86
|
-
importScriptSupported = false;
|
|
87
|
-
await imporModuleScripts(scripts);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (self.initCodec) {
|
|
91
|
-
self.initCodec();
|
|
92
|
-
}
|
|
93
|
-
config.CompressionStreamNative = self.CompressionStream;
|
|
94
|
-
config.DecompressionStreamNative = self.DecompressionStream;
|
|
95
|
-
if (self.Deflate) {
|
|
96
|
-
config.CompressionStream = new StreamAdapter(self.Deflate);
|
|
97
|
-
}
|
|
98
|
-
if (self.Inflate) {
|
|
99
|
-
config.DecompressionStream = new StreamAdapter(self.Inflate);
|
|
80
|
+
const { options, config } = message;
|
|
81
|
+
if (!initializedModule && !options.useCompressionStream) {
|
|
82
|
+
await initModule(message.config.wasmURI, message.config);
|
|
100
83
|
}
|
|
84
|
+
config.CompressionStream = self.CompressionStream;
|
|
85
|
+
config.DecompressionStream = self.DecompressionStream;
|
|
86
|
+
config.CompressionStreamZlib = CompressionStreamZlib;
|
|
87
|
+
config.DecompressionStreamZlib = DecompressionStreamZlib;
|
|
101
88
|
const strategy = { highWaterMark: 1 };
|
|
102
89
|
const readable = message.readable || new ReadableStream({
|
|
103
90
|
async pull(controller) {
|
|
@@ -148,12 +135,6 @@ async function init(message) {
|
|
|
148
135
|
}
|
|
149
136
|
}
|
|
150
137
|
|
|
151
|
-
async function imporModuleScripts(scripts) {
|
|
152
|
-
for (const script of scripts) {
|
|
153
|
-
await import(script);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
138
|
function sendMessage(message) {
|
|
158
139
|
let { value } = message;
|
|
159
140
|
if (value) {
|
|
@@ -177,4 +158,4 @@ function sendMessage(message) {
|
|
|
177
158
|
function sendErrorMessage(error = new Error("Unknown error")) {
|
|
178
159
|
const { message, stack, code, name, outputSize } = error;
|
|
179
160
|
postMessage({ error: { message, stack, code, name, outputSize } });
|
|
180
|
-
}
|
|
161
|
+
}
|
package/lib/core/zip-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -40,9 +40,7 @@ const PROPERTY_NAME_LAST_ACCESS_DATE = "lastAccessDate";
|
|
|
40
40
|
const PROPERTY_NAME_RAW_LAST_ACCESS_DATE = "rawLastAccessDate";
|
|
41
41
|
const PROPERTY_NAME_CREATION_DATE = "creationDate";
|
|
42
42
|
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
43
|
-
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
|
|
44
43
|
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
|
|
45
|
-
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
|
|
46
44
|
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
|
|
47
45
|
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
48
46
|
const PROPERTY_NAME_ZIP64 = "zip64";
|
|
@@ -60,8 +58,8 @@ const PROPERTY_NAMES = [
|
|
|
60
58
|
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPRESSED_SIZE, PROPERTY_NAME_UNCOMPRESSED_SIZE,
|
|
61
59
|
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
|
|
62
60
|
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
|
|
63
|
-
PROPERTY_NAME_DISK_NUMBER_START,
|
|
64
|
-
|
|
61
|
+
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
62
|
+
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
65
63
|
PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, PROPERTY_NAME_DIRECTORY,
|
|
66
64
|
PROPERTY_NAME_EXECUTABLE, PROPERTY_NAME_COMPRESSION_METHOD, PROPERTY_NAME_SIGNATURE, PROPERTY_NAME_EXTRA_FIELD,
|
|
67
65
|
"bitFlag", "filenameUTF8", "commentUTF8", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
|
|
@@ -90,9 +88,7 @@ export {
|
|
|
90
88
|
PROPERTY_NAME_RAW_LAST_ACCESS_DATE,
|
|
91
89
|
PROPERTY_NAME_CREATION_DATE,
|
|
92
90
|
PROPERTY_NAME_RAW_CREATION_DATE,
|
|
93
|
-
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE,
|
|
94
91
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
95
|
-
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
96
92
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
97
93
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
98
94
|
PROPERTY_NAME_ZIP64,
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -69,7 +69,8 @@ import {
|
|
|
69
69
|
HEADER_OFFSET_SIGNATURE,
|
|
70
70
|
HEADER_OFFSET_COMPRESSED_SIZE,
|
|
71
71
|
HEADER_OFFSET_UNCOMPRESSED_SIZE,
|
|
72
|
-
UNDEFINED_VALUE
|
|
72
|
+
UNDEFINED_VALUE,
|
|
73
|
+
COMPRESSION_METHOD_DEFLATE_64
|
|
73
74
|
} from "./constants.js";
|
|
74
75
|
import {
|
|
75
76
|
getConfiguration,
|
|
@@ -299,7 +300,7 @@ class ZipReader {
|
|
|
299
300
|
const directory =
|
|
300
301
|
(msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK)) ||
|
|
301
302
|
(unixCompatible && (((externalFileAttributes >> 16) & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_DIR)) ||
|
|
302
|
-
(rawFilename.length && rawFilename
|
|
303
|
+
(rawFilename.length && rawFilename.at(-1) == DIRECTORY_SIGNATURE.charCodeAt(0));
|
|
303
304
|
const executable = (unixCompatible && (((externalFileAttributes >> 16) & FILE_ATTR_UNIX_EXECUTABLE_MASK) != 0));
|
|
304
305
|
const offsetFileEntry = getUint32(directoryView, offset + 42) + prependedDataLength;
|
|
305
306
|
Object.assign(fileEntry, {
|
|
@@ -475,7 +476,7 @@ class ZipEntry {
|
|
|
475
476
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
476
477
|
}
|
|
477
478
|
}
|
|
478
|
-
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) && !passThrough) {
|
|
479
|
+
if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE && compressionMethod != COMPRESSION_METHOD_DEFLATE_64) && !passThrough) {
|
|
479
480
|
throw new Error(ERR_UNSUPPORTED_COMPRESSION);
|
|
480
481
|
}
|
|
481
482
|
if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
|
|
@@ -521,6 +522,11 @@ class ZipEntry {
|
|
|
521
522
|
checkOverlappingEntry = true;
|
|
522
523
|
}
|
|
523
524
|
const { onstart, onprogress, onend } = options;
|
|
525
|
+
const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
|
|
526
|
+
let useCompressionStream = getOptionValue(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
|
|
527
|
+
if (deflate64) {
|
|
528
|
+
useCompressionStream = false;
|
|
529
|
+
}
|
|
524
530
|
const workerOptions = {
|
|
525
531
|
options: {
|
|
526
532
|
codecType: CODEC_INFLATE,
|
|
@@ -535,8 +541,9 @@ class ZipEntry {
|
|
|
535
541
|
compressed: compressionMethod != 0 && !passThrough,
|
|
536
542
|
encrypted: zipEntry.encrypted && !passThrough,
|
|
537
543
|
useWebWorkers: getOptionValue(zipEntry, options, OPTION_USE_WEB_WORKERS),
|
|
538
|
-
useCompressionStream
|
|
544
|
+
useCompressionStream,
|
|
539
545
|
transferStreams: getOptionValue(zipEntry, options, OPTION_TRANSFER_STREAMS),
|
|
546
|
+
deflate64,
|
|
540
547
|
checkPasswordOnly
|
|
541
548
|
},
|
|
542
549
|
config,
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
3
3
|
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -96,8 +96,6 @@ import {
|
|
|
96
96
|
PROPERTY_NAME_LAST_MODIFICATION_DATE,
|
|
97
97
|
PROPERTY_NAME_LAST_ACCESS_DATE,
|
|
98
98
|
PROPERTY_NAME_CREATION_DATE,
|
|
99
|
-
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE,
|
|
100
|
-
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
101
99
|
PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
|
|
102
100
|
PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES,
|
|
103
101
|
PROPERTY_NAME_MS_DOS_COMPATIBLE,
|
|
@@ -374,9 +372,6 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
374
372
|
throw new Error(ERR_INVALID_VERSION);
|
|
375
373
|
}
|
|
376
374
|
let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, 0);
|
|
377
|
-
if (externalFileAttributes === 0) {
|
|
378
|
-
externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
|
|
379
|
-
}
|
|
380
375
|
if (!options[PROPERTY_NAME_DIRECTORY] && name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
381
376
|
options[PROPERTY_NAME_DIRECTORY] = true;
|
|
382
377
|
}
|
|
@@ -421,10 +416,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
421
416
|
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
|
|
422
417
|
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
423
418
|
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
424
|
-
|
|
425
|
-
if (internalFileAttributes === 0) {
|
|
426
|
-
internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
|
|
427
|
-
}
|
|
419
|
+
const internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, 0);
|
|
428
420
|
const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
|
|
429
421
|
let password, rawPassword;
|
|
430
422
|
if (!passThrough) {
|
|
@@ -435,14 +427,14 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
435
427
|
const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
|
|
436
428
|
const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
|
|
437
429
|
const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
|
|
438
|
-
const level = getOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
439
430
|
const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
|
|
440
431
|
const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
|
|
441
432
|
const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, false);
|
|
442
433
|
const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
|
|
443
434
|
const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
|
|
444
|
-
const useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
|
|
445
435
|
const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
|
|
436
|
+
let level = getOptionValue(zipWriter, options, OPTION_LEVEL);
|
|
437
|
+
let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
|
|
446
438
|
let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
|
|
447
439
|
if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
|
|
448
440
|
dataDescriptor = false;
|
|
@@ -450,6 +442,12 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
450
442
|
if (dataDescriptor === UNDEFINED_VALUE || zipCrypto) {
|
|
451
443
|
dataDescriptor = true;
|
|
452
444
|
}
|
|
445
|
+
if (level !== UNDEFINED_VALUE && level != 6) {
|
|
446
|
+
useCompressionStream = false;
|
|
447
|
+
}
|
|
448
|
+
if (!useCompressionStream && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
|
|
449
|
+
level = 0;
|
|
450
|
+
}
|
|
453
451
|
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
454
452
|
if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
|
|
455
453
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
@@ -534,7 +532,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
534
532
|
zip64DiskNumberStart,
|
|
535
533
|
password,
|
|
536
534
|
rawPassword,
|
|
537
|
-
level
|
|
535
|
+
level,
|
|
538
536
|
useWebWorkers,
|
|
539
537
|
encryptionStrength,
|
|
540
538
|
extendedTimestamp,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
/*
|
|
3
|
-
Copyright (c)
|
|
2
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
4
3
|
|
|
5
4
|
Redistribution and use in source and binary forms, with or without
|
|
6
5
|
modification, are permitted provided that the following conditions are met:
|
|
@@ -27,13 +26,12 @@
|
|
|
27
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
|
-
/*
|
|
29
|
+
/* eslint-disable quotes */
|
|
31
30
|
|
|
32
|
-
import "./
|
|
33
|
-
import { initShimAsyncCodec } from "./core/util/stream-codec-shim.js";
|
|
31
|
+
import { decompress } from "./util/mini-lz.js";
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
33
|
+
export function configureZlibModule(configure) {
|
|
34
|
+
const data = `__wasmBinary__`;
|
|
35
|
+
const uri = () => "data:application/wasm;base64," + decompress(data);
|
|
36
|
+
configure({ wasmURI: uri });
|
|
37
|
+
}
|