unzipit 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -1
- package/dist/unzipit-worker.js +1 -1
- package/dist/unzipit-worker.min.js +1 -1
- package/dist/unzipit-worker.module.js +1 -1
- package/dist/unzipit.js +2 -2
- package/dist/unzipit.min.js +2 -2
- package/dist/unzipit.module.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,13 +63,37 @@ async function readFiles(url) {
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
67
66
|
You can also pass a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob),
|
|
68
67
|
[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer),
|
|
69
68
|
[`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer),
|
|
70
69
|
[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray),
|
|
71
70
|
or your own `Reader`
|
|
72
71
|
|
|
72
|
+
For using without a builder/bundler grab `unzipit.min.js` or `unzipit.module.js` from
|
|
73
|
+
the [`dist`](https://github.com/greggman/unzipit/tree/master/dist) folder and
|
|
74
|
+
include with
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
import * as unzipit from `./unzipit.module.js`;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
or
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<script src="unzipit.min.js"></script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or vs CDN
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import * as unzipit from 'https://unpkg.com/unzipit@1.4.0/dist/unzipit.module.js';
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
or
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<script src="https://unpkg.com/unzipit@1.4.0/dist/unzipit.js"></script>
|
|
96
|
+
```
|
|
73
97
|
## Node
|
|
74
98
|
|
|
75
99
|
For node you need to make your own `Reader` or pass in an
|
|
@@ -477,6 +501,40 @@ size before asking for their content.
|
|
|
477
501
|
unzipit does not currently support encrypted zip files and will throw if you try to get the data for one.
|
|
478
502
|
Put it on the TODO list 😅
|
|
479
503
|
|
|
504
|
+
## File Attributes
|
|
505
|
+
|
|
506
|
+
If you want to make an unzip utilitiy using this library you'll need to be able to mark some files as executable.
|
|
507
|
+
That is unforutunately platform specific. For example, Windows has no concept of "mark a file as executable".
|
|
508
|
+
Each zip entry provides a `versionMadeBy` and `externalFileAttributes` property. You could theoretically use
|
|
509
|
+
that to set file attributes. For example
|
|
510
|
+
|
|
511
|
+
```js
|
|
512
|
+
fs.writeFileSync(filename, data);
|
|
513
|
+
if (process.platform === 'darwin' || process.platform === 'linux') {
|
|
514
|
+
const platform = entry.versionMadeBy >> 8;
|
|
515
|
+
const unix = 3;
|
|
516
|
+
const darwin = 13
|
|
517
|
+
if (entry.versionMadeBy === unix || entry.versionMadeBy === darwin) {
|
|
518
|
+
// no idea what's best here
|
|
519
|
+
// +- owner read
|
|
520
|
+
// |+- owner write
|
|
521
|
+
// ||+- owner execute
|
|
522
|
+
// |||+- group read
|
|
523
|
+
// ||||+- group write
|
|
524
|
+
// |||||+- group execute
|
|
525
|
+
// ||||||+- other read
|
|
526
|
+
// |||||||+- other write
|
|
527
|
+
// ||||||||+- other execute
|
|
528
|
+
// |||||||||
|
|
529
|
+
// VVVVVVVVV
|
|
530
|
+
let mod = (entry.externalFileAttributes >> 16) & 0b111111111; // all the bits
|
|
531
|
+
mod &= 0b111100100; // remove write and executable from group and other?
|
|
532
|
+
mod |= 0b110100100; // add in owner R/W, group R, other R
|
|
533
|
+
fs.chmodSync(filename, mod);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
480
538
|
## Other Limitations
|
|
481
539
|
|
|
482
540
|
unzipit only supports the uncompressed and deflate compression algorithms. Other algorithms are defined
|
package/dist/unzipit-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* unzipit@1.4.
|
|
1
|
+
/* unzipit@1.4.2, license MIT */
|
|
2
2
|
'use strict';(function(w){"function"===typeof define&&define.amd?define(w):w()})(function(){function w(a,b){var e=a.length;if(b<=e)return a;b=new Uint8Array(Math.max(e<<1,b));b.set(a,0);return b}function X(a,b,e,g){for(var f=0,c=0,m=g.length>>>1;c<e;){var p=a[c+b];g[c<<1]=0;g[(c<<1)+1]=p;p>f&&(f=p);c++}for(;c<m;)g[c<<1]=0,g[(c<<1)+1]=0,c++;return f}function z(a,b){var e=a.length,g,f;var c=d.bl_count;for(f=0;f<=b;f++)c[f]=0;for(f=1;f<e;f+=2)c[a[f]]++;f=d.next_code;var m=0;c[0]=0;for(g=1;g<=b;g++)m=
|
|
3
3
|
m+c[g-1]<<1,f[g]=m;for(b=0;b<e;b+=2)c=a[b+1],0!=c&&(a[b]=f[c],f[c]++)}function A(a,b,e){for(var g=a.length,f=d.rev15,c=0;c<g;c+=2)if(0!=a[c+1]){var m=a[c+1],p=c>>1<<4|m,t=b-m;m=a[c]<<t;for(t=m+(1<<t);m!=t;)e[f[m]>>>15-b]=p,m++}}function Y(a,b){for(var e=d.rev15,g=15-b,f=0;f<a.length;f+=2)a[f]=e[a[f]<<b-a[f+1]]>>>g}function x(a,b,e){return(a[b>>>3]|a[(b>>>3)+1]<<8)>>>(b&7)&(1<<e)-1}function K(a,b,e){return(a[b>>>3]|a[(b>>>3)+1]<<8|a[(b>>>3)+2]<<16)>>>(b&7)&(1<<e)-1}function L(a,b){return(a[b>>>3]|
|
|
4
4
|
a[(b>>>3)+1]<<8|a[(b>>>3)+2]<<16)>>>(b&7)}function fa(a){return a.arrayBuffer?a.arrayBuffer():new Promise((b,e)=>{const g=new FileReader;g.addEventListener("loadend",()=>{b(g.result)});g.addEventListener("error",e);g.readAsArrayBuffer(a)})}async function ha(a){a=await fa(a);return new Uint8Array(a)}const d=function(){var a=Uint16Array,b=Uint32Array;return{next_code:new a(16),bl_count:new a(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,
|
package/dist/unzipit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* unzipit@1.4.
|
|
1
|
+
/* unzipit@1.4.2, license MIT */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -430,7 +430,7 @@
|
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
function dynamicRequire(mod, request) {
|
|
433
|
-
return mod.require(request);
|
|
433
|
+
return mod.require ? mod.require(request) : {};
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
const workerHelper = (function() {
|
package/dist/unzipit.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* unzipit@1.4.
|
|
1
|
+
/* unzipit@1.4.2, license MIT */
|
|
2
2
|
'use strict';(function(z,G){"object"===typeof exports&&"undefined"!==typeof module?G(exports):"function"===typeof define&&define.amd?define(["exports"],G):(z="undefined"!==typeof globalThis?globalThis:z||self,G(z.unzipit={}))})(this,function(z){function G(a){return a.arrayBuffer?a.arrayBuffer():new Promise((b,c)=>{const e=new FileReader;e.addEventListener("loadend",()=>{b(e.result)});e.addEventListener("error",c);e.readAsArrayBuffer(a)})}async function na(a){a=await G(a);return new Uint8Array(a)}
|
|
3
3
|
function aa(a){return"undefined"!==typeof Blob&&a instanceof Blob}function I(a){return"undefined"!==typeof SharedArrayBuffer&&a instanceof SharedArrayBuffer}function R(a,b){var c=a.length;if(b<=c)return a;b=new Uint8Array(Math.max(c<<1,b));b.set(a,0);return b}function oa(a,b,c,e,d,h){for(var k=ba,f=ca,l=0;l<c;){var n=a[f(e,d)&b];d+=n&15;var u=n>>>4;if(15>=u)h[l]=u,l++;else{var x=n=0;16==u?(x=3+k(e,d,2),d+=2,n=h[l-1]):17==u?(x=3+k(e,d,3),d+=3):18==u&&(x=11+k(e,d,7),d+=7);for(u=l+x;l<u;)h[l]=n,l++}}return d}
|
|
4
4
|
function da(a,b,c,e){for(var d=0,h=0,k=e.length>>>1;h<c;){var f=a[h+b];e[h<<1]=0;e[(h<<1)+1]=f;f>d&&(d=f);h++}for(;h<k;)e[h<<1]=0,e[(h<<1)+1]=0,h++;return d}function J(a,b){var c=a.length,e,d;var h=g.bl_count;for(d=0;d<=b;d++)h[d]=0;for(d=1;d<c;d+=2)h[a[d]]++;d=g.next_code;var k=0;h[0]=0;for(e=1;e<=b;e++)k=k+h[e-1]<<1,d[e]=k;for(b=0;b<c;b+=2)h=a[b+1],0!=h&&(a[b]=d[h],d[h]++)}function K(a,b,c){for(var e=a.length,d=g.rev15,h=0;h<e;h+=2)if(0!=a[h+1]){var k=a[h+1],f=h>>1<<4|k,l=b-k;k=a[h]<<l;for(l=k+
|
|
@@ -24,7 +24,7 @@ this.length=parseInt(a.headers.get("content-length"));if(Number.isNaN(this.lengt
|
|
|
24
24
|
bl_count:new a(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],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],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],ldef:new a(32),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],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],ddef:new b(32),flmap:new a(512),
|
|
25
25
|
fltree:[],fdmap:new a(32),fdtree:[],lmap:new a(32768),ltree:[],ttree:[],dmap:new a(32768),dtree:[],imap:new a(512),itree:[],rev15:new a(32768),lhst:new b(286),dhst:new b(30),ihst:new b(19),lits:new b(15E3),strt:new a(65536),prev:new a(32768)}}();(function(){function a(e,d,h){for(;0!=d--;)e.push(0,h)}for(var b=0;32768>b;b++){var c=b;c=(c&2863311530)>>>1|(c&1431655765)<<1;c=(c&3435973836)>>>2|(c&858993459)<<2;c=(c&4042322160)>>>4|(c&252645135)<<4;c=(c&4278255360)>>>8|(c&16711935)<<8;g.rev15[b]=(c>>>
|
|
26
26
|
16|c<<16)>>>17}for(b=0;32>b;b++)g.ldef[b]=g.of0[b]<<3|g.exb[b],g.ddef[b]=g.df0[b]<<4|g.dxb[b];a(g.fltree,144,8);a(g.fltree,112,9);a(g.fltree,24,7);a(g.fltree,8,8);J(g.fltree,9);K(g.fltree,9,g.flmap);ea(g.fltree,9);a(g.fdtree,32,5);J(g.fdtree,5);K(g.fdtree,5,g.fdmap);ea(g.fdtree,5);a(g.itree,19,0);a(g.ltree,286,0);a(g.dtree,30,0);a(g.ttree,320,0)})();const ma={table:function(){for(var a=new Uint32Array(256),b=0;256>b;b++){for(var c=b,e=0;8>e;e++)c=c&1?3988292384^c>>>1:c>>>1;a[b]=c}return a}(),update:function(a,
|
|
27
|
-
b,c,e){for(var d=0;d<e;d++)a=ma.table[(a^b[c+d])&255]^a>>>8;return a},crc:function(a,b,c){return ma.update(4294967295,a,b,c)^4294967295}},y={numWorkers:1,workerURL:"",useWorkers:!1};let ta=0,U=0,P=!0;const O=[],D=[],B=[],N=new Map,V=function(){if(Ca){const {Worker:a}=module.require("worker_threads");return{async createWorker(b){return new a(b)},addEventListener(b,c){b.on("message",e=>{c({target:b,data:e})})},async terminate(b){await b.terminate()}}}return{async createWorker(a){try{return await T(a)}catch(c){console.warn("could not load worker:",
|
|
27
|
+
b,c,e){for(var d=0;d<e;d++)a=ma.table[(a^b[c+d])&255]^a>>>8;return a},crc:function(a,b,c){return ma.update(4294967295,a,b,c)^4294967295}},y={numWorkers:1,workerURL:"",useWorkers:!1};let ta=0,U=0,P=!0;const O=[],D=[],B=[],N=new Map,V=function(){if(Ca){const {Worker:a}=module.require?module.require("worker_threads"):{};return{async createWorker(b){return new a(b)},addEventListener(b,c){b.on("message",e=>{c({target:b,data:e})})},async terminate(b){await b.terminate()}}}return{async createWorker(a){try{return await T(a)}catch(c){console.warn("could not load worker:",
|
|
28
28
|
a)}let b;try{const c=await fetch(a,{mode:"cors"});if(!c.ok)throw Error(`could not load: ${a}`);b=await c.text();a=URL.createObjectURL(new Blob([b],{type:"application/javascript"}));const e=await T(a);y.workerURL=a;return e}catch(c){console.warn("could not load worker via fetch:",a)}if(void 0!==b)try{a=`data:application/javascript;base64,${btoa(b)}`;const c=await T(a);y.workerURL=a;return c}catch(c){console.warn("could not load worker via dataURI")}console.warn("workers will not be used");throw Error("can not start workers");
|
|
29
29
|
},addEventListener(a,b){a.addEventListener("message",b)},async terminate(a){a.terminate()}}}();class za{constructor(a,b){this._reader=a;this._rawEntry=b;this.name=b.name;this.nameBytes=b.nameBytes;this.size=b.uncompressedSize;this.compressedSize=b.compressedSize;this.comment=b.comment;this.commentBytes=b.commentBytes;this.compressionMethod=b.compressionMethod;a=b.lastModFileDate;var c=b.lastModFileTime;this.lastModDate=new Date((a>>9&127)+1980,(a>>5&15)-1,a&31,c>>11&31,c>>5&63,2*(c&31),0);this.isDirectory=
|
|
30
30
|
0===b.uncompressedSize&&b.name.endsWith("/");this.encrypted=!!(b.generalPurposeBitFlag&1);this.externalFileAttributes=b.externalFileAttributes;this.versionMadeBy=b.versionMadeBy}async blob(a="application/octet-stream"){return await Ba(this._reader,this._rawEntry,a)}async arrayBuffer(){return await Aa(this._reader,this._rawEntry)}async text(){const a=await this.arrayBuffer();return M(new Uint8Array(a))}async json(){const a=await this.text();return JSON.parse(a)}}const ya={unsigned(){return 0}},va=
|
package/dist/unzipit.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* unzipit@1.4.
|
|
1
|
+
/* unzipit@1.4.2, license MIT */
|
|
2
2
|
/* global SharedArrayBuffer, process */
|
|
3
3
|
|
|
4
4
|
function readBlobAsArrayBuffer(blob) {
|
|
@@ -424,7 +424,7 @@ function startWorker(url) {
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
function dynamicRequire(mod, request) {
|
|
427
|
-
return mod.require(request);
|
|
427
|
+
return mod.require ? mod.require(request) : {};
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
const workerHelper = (function() {
|