w-zip 1.0.9 → 1.0.13
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/.github/workflows/ci-test.yml +2 -1
- package/README.md +12 -13
- package/SECURITY.md +5 -0
- package/dist/w-zip.umd.js +2 -2
- package/dist/w-zip.umd.js.map +1 -1
- package/docs/index.html +1 -1
- package/docs/m7z.html +7 -7
- package/docs/m7z.mjs.html +26 -9
- package/docs/mZip.html +6 -6
- package/docs/mZip.mjs.html +25 -8
- package/package.json +3 -3
- package/src/checkTarget.mjs +35 -0
- package/src/m7z.mjs +25 -8
- package/src/mZip.mjs +24 -7
- package/testData/output7z/test2PW.7z +0 -0
- package/testData/outputZip/test2PW.zip +0 -0
package/docs/mZip.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
|
|
72
72
|
<dt class="tag-source">Source:</dt>
|
|
73
73
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
74
|
-
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#
|
|
74
|
+
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#line93">line 93</a>
|
|
75
75
|
</li></ul></dd>
|
|
76
76
|
|
|
77
77
|
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
|
|
125
125
|
<h5>Example</h5>
|
|
126
126
|
|
|
127
|
-
<pre class="prettyprint"><code>import wz from 'w-zip'
|
|
128
127
|
//zipFile
|
|
129
128
|
console.log('zipFile before')
|
|
130
129
|
console.log('zipFile', await wz.mZip.zipFile(fpSrc1, fpZip1))
|
|
131
130
|
console.log('zipFile after')
|
|
132
131
|
//zipFolder
|
|
133
132
|
console.log('zipFolder before')
|
|
134
133
|
console.log('zipFolder', await wz.mZip.zipFolder(fpSrc2, fpZip2))
|
|
135
134
|
console.log('zipFolder after')
|
|
136
135
|
//zipFolder with password
|
|
137
136
|
console.log('zipFolder with password before')
|
|
138
137
|
console.log('zipFolder with password', await wz.mZip.zipFolder(fpSrc2, fpZip2PW, { pw }))
|
|
139
138
|
console.log('zipFolder with password after')
|
|
140
139
|
//unzip
|
|
141
140
|
console.log('unzip1 before')
|
|
142
141
|
console.log('unzip1', await wz.mZip.unzip(fpZip1, fpUnzipExtract + '/test1'))
|
|
143
142
|
console.log('unzip1 after')
|
|
144
143
|
//unzip
|
|
145
144
|
console.log('unzip2 before')
|
|
146
145
|
console.log('unzip2', await wz.mZip.unzip(fpZip2, fpUnzipExtract + '/test2'))
|
|
147
146
|
console.log('unzip2 after')
|
|
148
147
|
//unzip with password
|
|
149
148
|
console.log('unzip2 with password before')
|
|
150
149
|
console.log('unzip2 with password', await wz.mZip.unzip(fpZip2PW, fpUnzipExtract + '/test2PW', { pw }))
|
|
151
150
|
console.log('unzip2 with password after')
|
|
152
151
|
.catch((err) => {
|
|
153
152
|
console.log(err)
|
|
154
153
|
})
|
|
154
|
+
<pre class="prettyprint"><code>import wz from 'w-zip'
|
|
155
155
|
//zipFile
|
|
156
156
|
console.log('zipFile before')
|
|
157
157
|
console.log('zipFile', await wz.mZip.zipFile(fpSrc1, fpZip1))
|
|
158
158
|
console.log('zipFile after')
|
|
159
159
|
//zipFolder
|
|
160
160
|
console.log('zipFolder before')
|
|
161
161
|
console.log('zipFolder', await wz.mZip.zipFolder(fpSrc2, fpZip2))
|
|
162
162
|
console.log('zipFolder after')
|
|
163
163
|
//zipFolder with password
|
|
164
164
|
console.log('zipFolder with password before')
|
|
165
165
|
console.log('zipFolder with password', await wz.mZip.zipFolder(fpSrc2, fpZip2PW, { pw }))
|
|
166
166
|
console.log('zipFolder with password after')
|
|
167
167
|
//unzip
|
|
168
168
|
console.log('unzip1 before')
|
|
169
169
|
console.log('unzip1', await wz.mZip.unzip(fpZip1, fpUnzipExtract + '/test1'))
|
|
170
170
|
console.log('unzip1 after')
|
|
171
171
|
//unzip
|
|
172
172
|
console.log('unzip2 before')
|
|
173
173
|
console.log('unzip2', await wz.mZip.unzip(fpZip2, fpUnzipExtract + '/test2'))
|
|
174
174
|
console.log('unzip2 after')
|
|
175
175
|
//unzip with password
|
|
176
176
|
console.log('unzip2 with password before')
|
|
177
177
|
console.log('unzip2 with password', await wz.mZip.unzip(fpZip2PW, fpUnzipExtract + '/test2PW', { pw }))
|
|
178
178
|
console.log('unzip2 with password after')
|
|
179
179
|
.catch((err) => {
|
|
180
180
|
console.log(err)
|
|
181
181
|
})
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
|
|
207
207
|
<dt class="tag-source">Source:</dt>
|
|
208
208
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
209
|
-
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#
|
|
209
|
+
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#line278">line 278</a>
|
|
210
210
|
</li></ul></dd>
|
|
211
211
|
|
|
212
212
|
|
|
@@ -523,7 +523,7 @@
|
|
|
523
523
|
|
|
524
524
|
<dt class="tag-source">Source:</dt>
|
|
525
525
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
526
|
-
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#
|
|
526
|
+
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#line107">line 107</a>
|
|
527
527
|
</li></ul></dd>
|
|
528
528
|
|
|
529
529
|
|
|
@@ -865,7 +865,7 @@
|
|
|
865
865
|
|
|
866
866
|
<dt class="tag-source">Source:</dt>
|
|
867
867
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
868
|
-
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#
|
|
868
|
+
<a href="mZip.mjs.html">mZip.mjs</a>, <a href="mZip.mjs.html#line192">line 192</a>
|
|
869
869
|
</li></ul></dd>
|
|
870
870
|
|
|
871
871
|
|
|
@@ -1072,7 +1072,7 @@
|
|
|
1072
1072
|
<br class="clear">
|
|
1073
1073
|
|
|
1074
1074
|
<footer>
|
|
1075
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu
|
|
1075
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Dec 16 2021 13:56:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1076
1076
|
</footer>
|
|
1077
1077
|
|
|
1078
1078
|
<script>prettyPrint();</script>
|
package/docs/mZip.mjs.html
CHANGED
|
@@ -50,6 +50,8 @@ import unzipper from 'unzipper'
|
|
|
50
50
|
import get from 'lodash/get'
|
|
51
51
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
52
52
|
import pmMap from 'wsemi/src/pmMap.mjs'
|
|
53
|
+
import getFileName from 'wsemi/src/getFileName.mjs'
|
|
54
|
+
import checkTarget from './checkTarget.mjs'
|
|
53
55
|
|
|
54
56
|
|
|
55
57
|
//registerFormat
|
|
@@ -114,22 +116,22 @@ archiver.registerFormat('zip-encrypted', archiverEnc)
|
|
|
114
116
|
* })
|
|
115
117
|
*
|
|
116
118
|
* // zipFile before
|
|
117
|
-
* // zipFile done:
|
|
119
|
+
* // zipFile done: test1.zip
|
|
118
120
|
* // zipFile after
|
|
119
121
|
* // zipFolder before
|
|
120
|
-
* // zipFolder done:
|
|
122
|
+
* // zipFolder done: test2.zip
|
|
121
123
|
* // zipFolder after
|
|
122
124
|
* // zipFolder with password before
|
|
123
|
-
* // zipFolder with password done:
|
|
125
|
+
* // zipFolder with password done: test2PW.zip
|
|
124
126
|
* // zipFolder with password after
|
|
125
127
|
* // unzip1 before
|
|
126
|
-
* // unzip1 done:
|
|
128
|
+
* // unzip1 done: test1
|
|
127
129
|
* // unzip1 after
|
|
128
130
|
* // unzip2 before
|
|
129
|
-
* // unzip2 done:
|
|
131
|
+
* // unzip2 done: test2
|
|
130
132
|
* // unzip2 after
|
|
131
133
|
* // unzip2 with password before
|
|
132
|
-
* // unzip2 with password done:
|
|
134
|
+
* // unzip2 with password done: test2PW
|
|
133
135
|
* // unzip2 with password after
|
|
134
136
|
*/
|
|
135
137
|
function mZip() {
|
|
@@ -156,6 +158,11 @@ function mZip() {
|
|
|
156
158
|
return Promise.reject('path of source is not file')
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
//check fpTar
|
|
162
|
+
if (!checkTarget(fpTar)) {
|
|
163
|
+
return Promise.reject('invalid fpSrc')
|
|
164
|
+
}
|
|
165
|
+
|
|
159
166
|
//default
|
|
160
167
|
let level = get(opt, 'level', 9)
|
|
161
168
|
let pw = get(opt, 'pw', '')
|
|
@@ -236,6 +243,11 @@ function mZip() {
|
|
|
236
243
|
return Promise.reject('path of source is not folder')
|
|
237
244
|
}
|
|
238
245
|
|
|
246
|
+
//check fpTar
|
|
247
|
+
if (!checkTarget(fpTar)) {
|
|
248
|
+
return Promise.reject('invalid fpSrc')
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
//default
|
|
240
252
|
let level = get(opt, 'level', 9)
|
|
241
253
|
let pw = get(opt, 'pw', '')
|
|
@@ -317,6 +329,11 @@ function mZip() {
|
|
|
317
329
|
return Promise.reject('path of source is not file')
|
|
318
330
|
}
|
|
319
331
|
|
|
332
|
+
//check fpTar
|
|
333
|
+
if (!checkTarget(fpTar)) {
|
|
334
|
+
return Promise.reject('invalid fpSrc')
|
|
335
|
+
}
|
|
336
|
+
|
|
320
337
|
//default
|
|
321
338
|
let pw = get(opt, 'pw', '')
|
|
322
339
|
|
|
@@ -382,7 +399,7 @@ function mZip() {
|
|
|
382
399
|
//extract
|
|
383
400
|
await extract(fpSrc, fpTar, pw)
|
|
384
401
|
|
|
385
|
-
return Promise.resolve('done: ' + fpTar)
|
|
402
|
+
return Promise.resolve('done: ' + getFileName(fpTar))
|
|
386
403
|
}
|
|
387
404
|
catch (err) {
|
|
388
405
|
return Promise.reject(err)
|
|
@@ -413,7 +430,7 @@ export default mZip()
|
|
|
413
430
|
<br class="clear">
|
|
414
431
|
|
|
415
432
|
<footer>
|
|
416
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu
|
|
433
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Thu Dec 16 2021 13:56:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
417
434
|
</footer>
|
|
418
435
|
|
|
419
436
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-zip",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "A compression tool with zip and 7z.",
|
|
5
5
|
"main": "dist/w-zip.umd.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"archiver-zip-encrypted": "^1.0.10",
|
|
9
9
|
"unzipper": "^0.10.11",
|
|
10
10
|
"lodash": "^4.17.21",
|
|
11
|
-
"wsemi": "^1.6.
|
|
11
|
+
"wsemi": "^1.6.34"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"w-package-tools": "^1.0.
|
|
14
|
+
"w-package-tools": "^1.0.59"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
3
|
+
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
4
|
+
import fsDeleteFolder from 'wsemi/src/fsDeleteFolder.mjs'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async function checkTarget(fpTar) {
|
|
8
|
+
|
|
9
|
+
//check fpTar
|
|
10
|
+
try {
|
|
11
|
+
|
|
12
|
+
//刪除儲存對象
|
|
13
|
+
if (fsIsFile(fpTar)) {
|
|
14
|
+
fs.unlinkSync(fpTar)
|
|
15
|
+
}
|
|
16
|
+
else if (fsIsFolder(fpTar)) {
|
|
17
|
+
fsDeleteFolder(fpTar)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//測試儲存fpTar成文字檔案
|
|
21
|
+
fs.writeFileSync(fpTar, 'test', 'utf8')
|
|
22
|
+
|
|
23
|
+
//刪除測試檔案
|
|
24
|
+
fs.unlinkSync(fpTar)
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export default checkTarget
|
package/src/m7z.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import get from 'lodash/get'
|
|
3
3
|
import execScript from 'wsemi/src/execScript.mjs'
|
|
4
|
+
import getFileName from 'wsemi/src/getFileName.mjs'
|
|
5
|
+
import checkTarget from './checkTarget.mjs'
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -65,22 +67,22 @@ import execScript from 'wsemi/src/execScript.mjs'
|
|
|
65
67
|
* })
|
|
66
68
|
*
|
|
67
69
|
* // zipFile before
|
|
68
|
-
* // zipFile finish:
|
|
70
|
+
* // zipFile finish: test1.7z
|
|
69
71
|
* // zipFile after
|
|
70
72
|
* // zipFolder before
|
|
71
|
-
* // zipFolder finish:
|
|
73
|
+
* // zipFolder finish: test2.7z
|
|
72
74
|
* // zipFolder after
|
|
73
75
|
* // zipFolder with password before
|
|
74
|
-
* // zipFolder with password finish:
|
|
76
|
+
* // zipFolder with password finish: test2PW.7z
|
|
75
77
|
* // zipFolder with password after
|
|
76
78
|
* // unzip1 before
|
|
77
|
-
* // unzip1 finish:
|
|
79
|
+
* // unzip1 finish: test1
|
|
78
80
|
* // unzip1 after
|
|
79
81
|
* // unzip2 before
|
|
80
|
-
* // unzip2 finish:
|
|
82
|
+
* // unzip2 finish: test2
|
|
81
83
|
* // unzip2 after
|
|
82
84
|
* // unzip2 with password before
|
|
83
|
-
* // unzip2 with password finish:
|
|
85
|
+
* // unzip2 with password finish: test2PW
|
|
84
86
|
* // unzip2 with password after
|
|
85
87
|
*/
|
|
86
88
|
function m7z() {
|
|
@@ -144,7 +146,7 @@ function m7z() {
|
|
|
144
146
|
*/
|
|
145
147
|
async function zipFile(fpSrc, fpTar, opt = {}) {
|
|
146
148
|
|
|
147
|
-
//check
|
|
149
|
+
//check fpSrc
|
|
148
150
|
if (!fs.existsSync(fpSrc)) {
|
|
149
151
|
return Promise.reject('invalid path of source file')
|
|
150
152
|
}
|
|
@@ -152,6 +154,11 @@ function m7z() {
|
|
|
152
154
|
return Promise.reject('path of source is not file')
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
//check fpTar
|
|
158
|
+
if (!checkTarget(fpTar)) {
|
|
159
|
+
return Promise.reject('invalid fpSrc')
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
//default
|
|
156
163
|
let level = get(opt, 'level', 9)
|
|
157
164
|
let pw = get(opt, 'pw', '')
|
|
@@ -196,6 +203,11 @@ function m7z() {
|
|
|
196
203
|
return Promise.reject('path of source is not folder')
|
|
197
204
|
}
|
|
198
205
|
|
|
206
|
+
//check fpTar
|
|
207
|
+
if (!checkTarget(fpTar)) {
|
|
208
|
+
return Promise.reject('invalid fpSrc')
|
|
209
|
+
}
|
|
210
|
+
|
|
199
211
|
//default
|
|
200
212
|
let level = get(opt, 'level', 9)
|
|
201
213
|
let pw = get(opt, 'pw', '')
|
|
@@ -239,6 +251,11 @@ function m7z() {
|
|
|
239
251
|
return Promise.reject('path of source is not file')
|
|
240
252
|
}
|
|
241
253
|
|
|
254
|
+
//check fpTar
|
|
255
|
+
if (!checkTarget(fpTar)) {
|
|
256
|
+
return Promise.reject('invalid fpSrc')
|
|
257
|
+
}
|
|
258
|
+
|
|
242
259
|
//default
|
|
243
260
|
let pw = get(opt, 'pw', '')
|
|
244
261
|
|
|
@@ -265,7 +282,7 @@ function m7z() {
|
|
|
265
282
|
}
|
|
266
283
|
|
|
267
284
|
return {
|
|
268
|
-
state: 'finish: ' + fpTar, //7z順利結束不代表就是順利完成加解壓縮
|
|
285
|
+
state: 'finish: ' + getFileName(fpTar), //7z順利結束不代表就是順利完成加解壓縮
|
|
269
286
|
msg7z: r,
|
|
270
287
|
}
|
|
271
288
|
}
|
package/src/mZip.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import unzipper from 'unzipper'
|
|
|
6
6
|
import get from 'lodash/get'
|
|
7
7
|
import genPm from 'wsemi/src/genPm.mjs'
|
|
8
8
|
import pmMap from 'wsemi/src/pmMap.mjs'
|
|
9
|
+
import getFileName from 'wsemi/src/getFileName.mjs'
|
|
10
|
+
import checkTarget from './checkTarget.mjs'
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
//registerFormat
|
|
@@ -70,22 +72,22 @@ archiver.registerFormat('zip-encrypted', archiverEnc)
|
|
|
70
72
|
* })
|
|
71
73
|
*
|
|
72
74
|
* // zipFile before
|
|
73
|
-
* // zipFile done:
|
|
75
|
+
* // zipFile done: test1.zip
|
|
74
76
|
* // zipFile after
|
|
75
77
|
* // zipFolder before
|
|
76
|
-
* // zipFolder done:
|
|
78
|
+
* // zipFolder done: test2.zip
|
|
77
79
|
* // zipFolder after
|
|
78
80
|
* // zipFolder with password before
|
|
79
|
-
* // zipFolder with password done:
|
|
81
|
+
* // zipFolder with password done: test2PW.zip
|
|
80
82
|
* // zipFolder with password after
|
|
81
83
|
* // unzip1 before
|
|
82
|
-
* // unzip1 done:
|
|
84
|
+
* // unzip1 done: test1
|
|
83
85
|
* // unzip1 after
|
|
84
86
|
* // unzip2 before
|
|
85
|
-
* // unzip2 done:
|
|
87
|
+
* // unzip2 done: test2
|
|
86
88
|
* // unzip2 after
|
|
87
89
|
* // unzip2 with password before
|
|
88
|
-
* // unzip2 with password done:
|
|
90
|
+
* // unzip2 with password done: test2PW
|
|
89
91
|
* // unzip2 with password after
|
|
90
92
|
*/
|
|
91
93
|
function mZip() {
|
|
@@ -112,6 +114,11 @@ function mZip() {
|
|
|
112
114
|
return Promise.reject('path of source is not file')
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
//check fpTar
|
|
118
|
+
if (!checkTarget(fpTar)) {
|
|
119
|
+
return Promise.reject('invalid fpSrc')
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
//default
|
|
116
123
|
let level = get(opt, 'level', 9)
|
|
117
124
|
let pw = get(opt, 'pw', '')
|
|
@@ -192,6 +199,11 @@ function mZip() {
|
|
|
192
199
|
return Promise.reject('path of source is not folder')
|
|
193
200
|
}
|
|
194
201
|
|
|
202
|
+
//check fpTar
|
|
203
|
+
if (!checkTarget(fpTar)) {
|
|
204
|
+
return Promise.reject('invalid fpSrc')
|
|
205
|
+
}
|
|
206
|
+
|
|
195
207
|
//default
|
|
196
208
|
let level = get(opt, 'level', 9)
|
|
197
209
|
let pw = get(opt, 'pw', '')
|
|
@@ -273,6 +285,11 @@ function mZip() {
|
|
|
273
285
|
return Promise.reject('path of source is not file')
|
|
274
286
|
}
|
|
275
287
|
|
|
288
|
+
//check fpTar
|
|
289
|
+
if (!checkTarget(fpTar)) {
|
|
290
|
+
return Promise.reject('invalid fpSrc')
|
|
291
|
+
}
|
|
292
|
+
|
|
276
293
|
//default
|
|
277
294
|
let pw = get(opt, 'pw', '')
|
|
278
295
|
|
|
@@ -338,7 +355,7 @@ function mZip() {
|
|
|
338
355
|
//extract
|
|
339
356
|
await extract(fpSrc, fpTar, pw)
|
|
340
357
|
|
|
341
|
-
return Promise.resolve('done: ' + fpTar)
|
|
358
|
+
return Promise.resolve('done: ' + getFileName(fpTar))
|
|
342
359
|
}
|
|
343
360
|
catch (err) {
|
|
344
361
|
return Promise.reject(err)
|
|
Binary file
|
|
Binary file
|