unzipit 1.4.2 → 2.0.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.
@@ -1,324 +1,36 @@
1
- /* unzipit@1.4.2, license MIT */
2
- function inflate(data, buf) {
3
- var u8=Uint8Array;
4
- if(data[0]==3 && data[1]==0) return (buf ? buf : new u8(0));
5
- var bitsF = _bitsF, bitsE = _bitsE, decodeTiny = _decodeTiny, get17 = _get17;
6
-
7
- var noBuf = (buf==null);
8
- if(noBuf) buf = new u8((data.length>>>2)<<3);
9
-
10
- var BFINAL=0, BTYPE=0, HLIT=0, HDIST=0, HCLEN=0, ML=0, MD=0;
11
- var off = 0, pos = 0;
12
- var lmap, dmap;
13
-
14
- while(BFINAL==0) {
15
- BFINAL = bitsF(data, pos , 1);
16
- BTYPE = bitsF(data, pos+1, 2); pos+=3;
17
- //console.log(BFINAL, BTYPE);
18
-
19
- if(BTYPE==0) {
20
- if((pos&7)!=0) pos+=8-(pos&7);
21
- var p8 = (pos>>>3)+4, len = data[p8-4]|(data[p8-3]<<8); //console.log(len);//bitsF(data, pos, 16),
22
- if(noBuf) buf=_check(buf, off+len);
23
- buf.set(new u8(data.buffer, data.byteOffset+p8, len), off);
24
- //for(var i=0; i<len; i++) buf[off+i] = data[p8+i];
25
- //for(var i=0; i<len; i++) if(buf[off+i] != data[p8+i]) throw "e";
26
- pos = ((p8+len)<<3); off+=len; continue;
27
- }
28
- if(noBuf) buf=_check(buf, off+(1<<17)); // really not enough in many cases (but PNG and ZIP provide buffer in advance)
29
- if(BTYPE==1) { lmap = U.flmap; dmap = U.fdmap; ML = (1<<9)-1; MD = (1<<5)-1; }
30
- if(BTYPE==2) {
31
- HLIT = bitsE(data, pos , 5)+257;
32
- HDIST = bitsE(data, pos+ 5, 5)+ 1;
33
- HCLEN = bitsE(data, pos+10, 4)+ 4; pos+=14;
34
- for(var i=0; i<38; i+=2) { U.itree[i]=0; U.itree[i+1]=0; }
35
- var tl = 1;
36
- for(var i=0; i<HCLEN; i++) { var l=bitsE(data, pos+i*3, 3); U.itree[(U.ordr[i]<<1)+1] = l; if(l>tl)tl=l; } pos+=3*HCLEN; //console.log(itree);
37
- makeCodes(U.itree, tl);
38
- codes2map(U.itree, tl, U.imap);
39
-
40
- lmap = U.lmap; dmap = U.dmap;
41
-
42
- pos = decodeTiny(U.imap, (1<<tl)-1, HLIT+HDIST, data, pos, U.ttree);
43
- var mx0 = _copyOut(U.ttree, 0, HLIT , U.ltree); ML = (1<<mx0)-1;
44
- var mx1 = _copyOut(U.ttree, HLIT, HDIST, U.dtree); MD = (1<<mx1)-1;
45
-
46
- //var ml = decodeTiny(U.imap, (1<<tl)-1, HLIT , data, pos, U.ltree); ML = (1<<(ml>>>24))-1; pos+=(ml&0xffffff);
47
- makeCodes(U.ltree, mx0);
48
- codes2map(U.ltree, mx0, lmap);
49
-
50
- //var md = decodeTiny(U.imap, (1<<tl)-1, HDIST, data, pos, U.dtree); MD = (1<<(md>>>24))-1; pos+=(md&0xffffff);
51
- makeCodes(U.dtree, mx1);
52
- codes2map(U.dtree, mx1, dmap);
53
- }
54
- //var ooff=off, opos=pos;
55
- while(true) {
56
- var code = lmap[get17(data, pos) & ML]; pos += code&15;
57
- var lit = code>>>4; //U.lhst[lit]++;
58
- if((lit>>>8)==0) { buf[off++] = lit; }
59
- else if(lit==256) { break; }
60
- else {
61
- var end = off+lit-254;
62
- if(lit>264) { var ebs = U.ldef[lit-257]; end = off + (ebs>>>3) + bitsE(data, pos, ebs&7); pos += ebs&7; }
63
- //dst[end-off]++;
64
-
65
- var dcode = dmap[get17(data, pos) & MD]; pos += dcode&15;
66
- var dlit = dcode>>>4;
67
- var dbs = U.ddef[dlit], dst = (dbs>>>4) + bitsF(data, pos, dbs&15); pos += dbs&15;
68
-
69
- //var o0 = off-dst, stp = Math.min(end-off, dst);
70
- //if(stp>20) while(off<end) { buf.copyWithin(off, o0, o0+stp); off+=stp; } else
71
- //if(end-dst<=off) buf.copyWithin(off, off-dst, end-dst); else
72
- //if(dst==1) buf.fill(buf[off-1], off, end); else
73
- if(noBuf) buf=_check(buf, off+(1<<17));
74
- while(off<end) { buf[off]=buf[off++-dst]; buf[off]=buf[off++-dst]; buf[off]=buf[off++-dst]; buf[off]=buf[off++-dst]; }
75
- off=end;
76
- //while(off!=end) { buf[off]=buf[off++-dst]; }
77
- }
78
- }
79
- //console.log(off-ooff, (pos-opos)>>>3);
80
- }
81
- //console.log(dst);
82
- //console.log(tlen, dlen, off-tlen+tcnt);
83
- return buf.length==off ? buf : buf.slice(0,off);
84
- }
85
- function _check(buf, len) {
86
- var bl=buf.length; if(len<=bl) return buf;
87
- var nbuf = new Uint8Array(Math.max(bl<<1,len)); nbuf.set(buf,0);
88
- //for(var i=0; i<bl; i+=4) { nbuf[i]=buf[i]; nbuf[i+1]=buf[i+1]; nbuf[i+2]=buf[i+2]; nbuf[i+3]=buf[i+3]; }
89
- return nbuf;
90
- }
91
-
92
- function _decodeTiny(lmap, LL, len, data, pos, tree) {
93
- var bitsE = _bitsE, get17 = _get17;
94
- var i = 0;
95
- while(i<len) {
96
- var code = lmap[get17(data, pos)&LL]; pos+=code&15;
97
- var lit = code>>>4;
98
- if(lit<=15) { tree[i]=lit; i++; }
99
- else {
100
- var ll = 0, n = 0;
101
- if(lit==16) {
102
- n = (3 + bitsE(data, pos, 2)); pos += 2; ll = tree[i-1];
103
- }
104
- else if(lit==17) {
105
- n = (3 + bitsE(data, pos, 3)); pos += 3;
106
- }
107
- else if(lit==18) {
108
- n = (11 + bitsE(data, pos, 7)); pos += 7;
109
- }
110
- var ni = i+n;
111
- while(i<ni) { tree[i]=ll; i++; }
112
- }
113
- }
114
- return pos;
115
- }
116
- function _copyOut(src, off, len, tree) {
117
- var mx=0, i=0, tl=tree.length>>>1;
118
- while(i<len) { var v=src[i+off]; tree[(i<<1)]=0; tree[(i<<1)+1]=v; if(v>mx)mx=v; i++; }
119
- while(i<tl ) { tree[(i<<1)]=0; tree[(i<<1)+1]=0; i++; }
120
- return mx;
121
- }
122
-
123
- function makeCodes(tree, MAX_BITS) { // code, length
124
- var max_code = tree.length;
125
- var code, bits, n, i, len;
126
-
127
- var bl_count = U.bl_count; for(var i=0; i<=MAX_BITS; i++) bl_count[i]=0;
128
- for(i=1; i<max_code; i+=2) bl_count[tree[i]]++;
129
-
130
- var next_code = U.next_code; // smallest code for each length
131
-
132
- code = 0;
133
- bl_count[0] = 0;
134
- for (bits = 1; bits <= MAX_BITS; bits++) {
135
- code = (code + bl_count[bits-1]) << 1;
136
- next_code[bits] = code;
137
- }
138
-
139
- for (n = 0; n < max_code; n+=2) {
140
- len = tree[n+1];
141
- if (len != 0) {
142
- tree[n] = next_code[len];
143
- next_code[len]++;
144
- }
145
- }
146
- }
147
- function codes2map(tree, MAX_BITS, map) {
148
- var max_code = tree.length;
149
- var r15 = U.rev15;
150
- for(var i=0; i<max_code; i+=2) if(tree[i+1]!=0) {
151
- var lit = i>>1;
152
- var cl = tree[i+1], val = (lit<<4)|cl; // : (0x8000 | (U.of0[lit-257]<<7) | (U.exb[lit-257]<<4) | cl);
153
- var rest = (MAX_BITS-cl), i0 = tree[i]<<rest, i1 = i0 + (1<<rest);
154
- //tree[i]=r15[i0]>>>(15-MAX_BITS);
155
- while(i0!=i1) {
156
- var p0 = r15[i0]>>>(15-MAX_BITS);
157
- map[p0]=val; i0++;
158
- }
159
- }
160
- }
161
- function revCodes(tree, MAX_BITS) {
162
- var r15 = U.rev15, imb = 15-MAX_BITS;
163
- for(var i=0; i<tree.length; i+=2) { var i0 = (tree[i]<<(MAX_BITS-tree[i+1])); tree[i] = r15[i0]>>>imb; }
164
- }
165
-
166
- function _bitsE(dt, pos, length) { return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) )>>>(pos&7))&((1<<length)-1); }
167
- function _bitsF(dt, pos, length) { return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16))>>>(pos&7))&((1<<length)-1); }
168
- /*
169
- function _get9(dt, pos) {
170
- return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8))>>>(pos&7))&511;
171
- } */
172
- function _get17(dt, pos) { // return at least 17 meaningful bytes
173
- return (dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16) )>>>(pos&7);
174
- }
175
- const U = function(){
176
- var u16=Uint16Array, u32=Uint32Array;
177
- return {
178
- next_code : new u16(16),
179
- bl_count : new u16(16),
180
- ordr : [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ],
181
- of0 : [3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],
182
- exb : [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, 0, 0, 0],
183
- ldef : new u16(32),
184
- df0 : [1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 65535, 65535],
185
- dxb : [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, 0, 0],
186
- ddef : new u32(32),
187
- flmap: new u16( 512), fltree: [],
188
- fdmap: new u16( 32), fdtree: [],
189
- lmap : new u16(32768), ltree : [], ttree:[],
190
- dmap : new u16(32768), dtree : [],
191
- imap : new u16( 512), itree : [],
192
- //rev9 : new u16( 512)
193
- rev15: new u16(1<<15),
194
- lhst : new u32(286), dhst : new u32( 30), ihst : new u32(19),
195
- lits : new u32(15000),
196
- strt : new u16(1<<16),
197
- prev : new u16(1<<15)
198
- };
199
- } ();
200
-
201
- (function(){
202
- var len = 1<<15;
203
- for(var i=0; i<len; i++) {
204
- var x = i;
205
- x = (((x & 0xaaaaaaaa) >>> 1) | ((x & 0x55555555) << 1));
206
- x = (((x & 0xcccccccc) >>> 2) | ((x & 0x33333333) << 2));
207
- x = (((x & 0xf0f0f0f0) >>> 4) | ((x & 0x0f0f0f0f) << 4));
208
- x = (((x & 0xff00ff00) >>> 8) | ((x & 0x00ff00ff) << 8));
209
- U.rev15[i] = (((x >>> 16) | (x << 16)))>>>17;
210
- }
211
-
212
- function pushV(tgt, n, sv) { while(n--!=0) tgt.push(0,sv); }
213
-
214
- for(var i=0; i<32; i++) { U.ldef[i]=(U.of0[i]<<3)|U.exb[i]; U.ddef[i]=(U.df0[i]<<4)|U.dxb[i]; }
215
-
216
- pushV(U.fltree, 144, 8); pushV(U.fltree, 255-143, 9); pushV(U.fltree, 279-255, 7); pushV(U.fltree,287-279,8);
217
- /*
218
- var i = 0;
219
- for(; i<=143; i++) U.fltree.push(0,8);
220
- for(; i<=255; i++) U.fltree.push(0,9);
221
- for(; i<=279; i++) U.fltree.push(0,7);
222
- for(; i<=287; i++) U.fltree.push(0,8);
223
- */
224
- makeCodes(U.fltree, 9);
225
- codes2map(U.fltree, 9, U.flmap);
226
- revCodes (U.fltree, 9);
227
-
228
- pushV(U.fdtree,32,5);
229
- //for(i=0;i<32; i++) U.fdtree.push(0,5);
230
- makeCodes(U.fdtree, 5);
231
- codes2map(U.fdtree, 5, U.fdmap);
232
- revCodes (U.fdtree, 5);
233
-
234
- pushV(U.itree,19,0); pushV(U.ltree,286,0); pushV(U.dtree,30,0); pushV(U.ttree,320,0);
235
- /*
236
- for(var i=0; i< 19; i++) U.itree.push(0,0);
237
- for(var i=0; i<286; i++) U.ltree.push(0,0);
238
- for(var i=0; i< 30; i++) U.dtree.push(0,0);
239
- for(var i=0; i<320; i++) U.ttree.push(0,0);
240
- */
241
- })();
242
-
243
- const crc = {
244
- table : ( function() {
245
- var tab = new Uint32Array(256);
246
- for (var n=0; n<256; n++) {
247
- var c = n;
248
- for (var k=0; k<8; k++) {
249
- if (c & 1) c = 0xedb88320 ^ (c >>> 1);
250
- else c = c >>> 1;
251
- }
252
- tab[n] = c; }
253
- return tab; })(),
254
- update : function(c, buf, off, len) {
255
- for (var i=0; i<len; i++) c = crc.table[(c ^ buf[off+i]) & 0xff] ^ (c >>> 8);
256
- return c;
257
- },
258
- crc : function(b,o,l) { return crc.update(0xffffffff,b,o,l) ^ 0xffffffff; }
259
- };
260
-
261
- function inflateRaw(file, buf) { return inflate(file, buf); }
262
-
263
- /* global SharedArrayBuffer, process */
264
-
1
+ /* unzipit@2.0.0, license MIT */
2
+ var _a, _b;
265
3
  function readBlobAsArrayBuffer(blob) {
266
- if (blob.arrayBuffer) {
267
- return blob.arrayBuffer();
268
- }
269
- return new Promise((resolve, reject) => {
270
- const reader = new FileReader();
271
- reader.addEventListener('loadend', () => {
272
- resolve(reader.result);
4
+ if (blob.arrayBuffer) {
5
+ return blob.arrayBuffer();
6
+ }
7
+ return new Promise((resolve, reject) => {
8
+ const reader = new FileReader();
9
+ reader.addEventListener('loadend', () => {
10
+ resolve(reader.result);
11
+ });
12
+ reader.addEventListener('error', reject);
13
+ reader.readAsArrayBuffer(blob);
273
14
  });
274
- reader.addEventListener('error', reject);
275
- reader.readAsArrayBuffer(blob);
276
- });
277
15
  }
278
-
279
16
  async function readBlobAsUint8Array(blob) {
280
- const arrayBuffer = await readBlobAsArrayBuffer(blob);
281
- return new Uint8Array(arrayBuffer);
17
+ const arrayBuffer = await readBlobAsArrayBuffer(blob);
18
+ return new Uint8Array(arrayBuffer);
282
19
  }
283
-
284
20
  function isBlob(v) {
285
- return typeof Blob !== 'undefined' && v instanceof Blob;
21
+ return typeof Blob !== 'undefined' && v instanceof Blob;
286
22
  }
23
+ const isNode = (typeof process !== 'undefined') &&
24
+ !!(process === null || process === void 0 ? void 0 : process.versions) &&
25
+ (typeof ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== 'undefined') &&
26
+ (typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.electron) === 'undefined');
287
27
 
288
- const isNode =
289
- (typeof process !== 'undefined') &&
290
- process.versions &&
291
- (typeof process.versions.node !== 'undefined') &&
292
- (typeof process.versions.electron === 'undefined');
293
-
294
- /* global require */
295
-
28
+ /* global DecompressionStream */
296
29
  // note: we only handle the inflate portion in a worker
297
30
  // every other part is already async and JavaScript
298
31
  // is non blocking. I suppose if you had a million entry
299
32
  // zip file then the loop going through the directory
300
33
  // might take time but that's an unlikely situation.
301
-
302
- const msgHelper = (function() {
303
- if (isNode) {
304
- const { parentPort } = require('worker_threads');
305
-
306
- return {
307
- postMessage: parentPort.postMessage.bind(parentPort),
308
- addEventListener: parentPort.on.bind(parentPort),
309
- };
310
- } else {
311
- return {
312
- postMessage: self.postMessage.bind(self),
313
- addEventListener(type, fn) {
314
- self.addEventListener(type, (e) => {
315
- fn(e.data);
316
- });
317
- },
318
- };
319
- }
320
- }());
321
-
322
34
  // class InflateRequest {
323
35
  // id: string,
324
36
  // src: ArrayBuffer, SharedArrayBuffer, blob
@@ -330,53 +42,77 @@ const msgHelper = (function() {
330
42
  // then 50 blobs will be asked to be read at once.
331
43
  // If feels like that should happen at a higher level (user code)
332
44
  // or a lower level (the browser)?
333
- async function inflate$1(req) {
334
- const {id, src, uncompressedSize, type} = req;
335
- try {
336
- let srcData;
337
- if (isBlob(src)) {
338
- srcData = await readBlobAsUint8Array(src);
339
- } else {
340
- srcData = new Uint8Array(src);
45
+ async function decompressRaw(src) {
46
+ const ds = new DecompressionStream('deflate-raw');
47
+ const writer = ds.writable.getWriter();
48
+ writer.write(src).then(() => writer.close()).catch(() => { });
49
+ const chunks = [];
50
+ const reader = ds.readable.getReader();
51
+ for (;;) {
52
+ const { done, value } = await reader.read();
53
+ if (done) {
54
+ break;
55
+ }
56
+ chunks.push(value);
57
+ }
58
+ const size = chunks.reduce((s, c) => s + c.byteLength, 0);
59
+ const result = new Uint8Array(size);
60
+ let offset = 0;
61
+ for (const chunk of chunks) {
62
+ result.set(chunk, offset);
63
+ offset += chunk.byteLength;
64
+ }
65
+ return result;
66
+ }
67
+ async function inflate(req, postMessage) {
68
+ const { id, src, type } = req;
69
+ try {
70
+ const srcData = isBlob(src)
71
+ ? await readBlobAsUint8Array(src)
72
+ : new Uint8Array(src);
73
+ const dstData = await decompressRaw(srcData);
74
+ const transferables = [];
75
+ let data;
76
+ if (type) {
77
+ data = new Blob([dstData], { type });
78
+ }
79
+ else {
80
+ data = dstData.buffer;
81
+ transferables.push(data);
82
+ }
83
+ postMessage({ id, data }, transferables);
341
84
  }
342
- const dstData = new Uint8Array(uncompressedSize);
343
- inflateRaw(srcData, dstData);
344
- const transferables = [];
345
- let data;
346
- if (type) {
347
- data = new Blob([dstData], {type});
348
- } else {
349
- data = dstData.buffer;
350
- transferables.push(data);
85
+ catch (e) {
86
+ console.error(e);
87
+ postMessage({ id, error: `${e}` });
351
88
  }
352
- msgHelper.postMessage({
353
- id,
354
- data,
355
- }, transferables);
356
- } catch (e) {
357
- console.error(e);
358
- msgHelper.postMessage({
359
- id,
360
- error: `${e.toString()}`,
89
+ }
90
+ function handleMessage(msg, postMessage) {
91
+ const { type, data } = msg;
92
+ if (type === 'inflate') {
93
+ inflate(data, postMessage);
94
+ }
95
+ else {
96
+ throw new Error('no handler for type: ' + type);
97
+ }
98
+ }
99
+ if (isNode) {
100
+ // Use dynamic import so this works in both CJS and ESM contexts.
101
+ // The import of a built-in resolves before any messages can arrive.
102
+ import('worker_threads').then(({ parentPort }) => {
103
+ parentPort.on('message', (msg) => {
104
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
+ handleMessage(msg, (m, t) => parentPort.postMessage(m, t));
106
+ });
361
107
  });
362
- }
363
108
  }
364
-
365
- const handlers = {
366
- inflate: inflate$1,
367
- };
368
-
369
- msgHelper.addEventListener('message', function(e) {
370
- const {type, data} = e;
371
- const fn = handlers[type];
372
- if (!fn) {
373
- throw new Error('no handler for type: ' + type);
374
- }
375
- fn(data);
376
- });
377
-
378
- if (!isNode) {
379
- // needed for firefox AFAICT as there so no other
380
- // way to know a worker loaded successfully.?
381
- msgHelper.postMessage('start');
109
+ else {
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ const workerSelf = self;
112
+ workerSelf.addEventListener('message', (e) => {
113
+ handleMessage(e.data, (m, t) => workerSelf.postMessage(m, t));
114
+ });
115
+ // needed for firefox AFAICT as there is no other
116
+ // way to know a worker loaded successfully.
117
+ workerSelf.postMessage('start');
382
118
  }
package/dist/unzipit.d.ts CHANGED
@@ -1,57 +1,74 @@
1
- export type ZipInfo = {
2
- zip: Zip,
3
- entries: {[key: string]: ZipEntry},
4
- };
5
-
6
- export type ZipInfoRaw = {
7
- zip: Zip,
8
- entries: ZipEntry[],
9
- };
10
-
11
- export type Zip = {
12
- comment: string, // the comment for the zip file
13
- commentBytes: Uint8Array, // the raw data for comment, see nameBytes
14
- };
15
-
16
- export type ZipEntry = {
17
- blob(type?: string): Promise<Blob>, // returns a Blob for this entry
18
- // (optional type as in 'image/jpeg')
19
- arrayBuffer(): Promise<ArrayBuffer>, // returns an ArrayBuffer for this entry
20
- text(): Promise<string>, // returns text, assumes the text is valid utf8.
21
- // If you want more options decode arrayBuffer yourself
22
- json(): Promise<any>, // returns text with JSON.parse called on it.
23
- // If you want more options decode arrayBuffer yourself
24
- name: string, // name of entry
25
- nameBytes: Uint8Array, // raw name of entry (see notes)
26
- size: number, // size in bytes
27
- compressedSize: number, // size before decompressing
28
- comment: string, // the comment for this entry
29
- commentBytes: Uint8Array, // the raw comment for this entry
30
- lastModDate: Date, // a Date
31
- isDirectory: boolean, // True if directory
32
- encrypted: boolean, // True if encrypted
33
- externalFileAttributes: number, // platform specific file attributes
34
- versionMadeBy: number, // platform that made this file
35
- };
36
-
37
- export interface Reader {
38
- getLength(): Promise<number>,
39
- read(offset: number, size: number): Promise<Uint8Array>,
1
+ import ArrayBufferReader from './ArrayBufferReader.js';
2
+ import BlobReader from './BlobReader.js';
3
+ export { ArrayBufferReader, BlobReader };
4
+ export * from './HTTPRangeReader.js';
5
+ export type { Reader } from './BlobReader.js';
6
+ export type { UnzipitOptions } from './inflate.js';
7
+ import type { Reader } from './BlobReader.js';
8
+ export interface Zip {
9
+ comment: string;
10
+ commentBytes: Uint8Array;
11
+ }
12
+ export interface ZipInfoRaw {
13
+ zip: Zip;
14
+ entries: ZipEntry[];
15
+ }
16
+ export interface ZipInfo {
17
+ zip: Zip;
18
+ entries: {
19
+ [key: string]: ZipEntry;
20
+ };
40
21
  }
41
-
42
- export type UnzipitOptions = {
43
- useWorkers?: boolean;
44
- workerURL?: string;
45
- numWorkers?: number;
46
- };
47
-
48
22
  export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array;
49
-
50
- export class HTTPRangeReader {
51
- constructor(url: string);
23
+ interface ExtraField {
24
+ id: number;
25
+ data: Uint8Array;
26
+ }
27
+ interface RawEntry {
28
+ versionMadeBy: number;
29
+ versionNeededToExtract: number;
30
+ generalPurposeBitFlag: number;
31
+ compressionMethod: number;
32
+ lastModFileTime: number;
33
+ lastModFileDate: number;
34
+ crc32: number;
35
+ compressedSize: number;
36
+ uncompressedSize: number;
37
+ fileNameLength: number;
38
+ extraFieldLength: number;
39
+ fileCommentLength: number;
40
+ internalFileAttributes: number;
41
+ externalFileAttributes: number;
42
+ relativeOffsetOfLocalHeader: number;
43
+ nameBytes: Uint8Array;
44
+ name: string;
45
+ extraFields: ExtraField[];
46
+ commentBytes: Uint8Array;
47
+ comment: string;
48
+ fileName?: string;
49
+ }
50
+ export declare class ZipEntry {
51
+ private _reader;
52
+ private _rawEntry;
53
+ name: string;
54
+ nameBytes: Uint8Array;
55
+ size: number;
56
+ compressedSize: number;
57
+ comment: string;
58
+ commentBytes: Uint8Array;
59
+ compressionMethod: number;
60
+ lastModDate: Date;
61
+ isDirectory: boolean;
62
+ encrypted: boolean;
63
+ externalFileAttributes: number;
64
+ versionMadeBy: number;
65
+ constructor(reader: Reader, rawEntry: RawEntry);
66
+ blob(type?: string): Promise<Blob>;
67
+ arrayBuffer(): Promise<ArrayBuffer>;
68
+ text(): Promise<string>;
69
+ json(): Promise<any>;
52
70
  }
53
-
54
- export function unzip(src: string | ArrayBuffer | TypedArray | Blob | Reader): Promise<ZipInfo>;
55
- export function unzipRaw(src: string | ArrayBuffer | TypedArray | Blob | Reader): Promise<ZipInfoRaw>;
56
- export function setOptions(options: UnzipitOptions): void;
57
- export function cleanup(): void;
71
+ export declare function setOptions(options: import('./inflate').UnzipitOptions): void;
72
+ export declare function unzipRaw(source: string | ArrayBuffer | TypedArray | SharedArrayBuffer | Blob | Reader): Promise<ZipInfoRaw>;
73
+ export declare function unzip(source: string | ArrayBuffer | TypedArray | SharedArrayBuffer | Blob | Reader): Promise<ZipInfo>;
74
+ export declare function cleanup(): void;