cross-zip 3.1.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/dependabot.yml +15 -0
- package/.github/workflows/ci.yml +23 -0
- package/README.md +3 -3
- package/index.js +18 -19
- package/package.json +3 -3
- package/test/unzip.js +24 -21
- package/test/zip.js +16 -17
- package/.travis.yml +0 -9
@@ -0,0 +1,15 @@
|
|
1
|
+
version: 2
|
2
|
+
updates:
|
3
|
+
- package-ecosystem: npm
|
4
|
+
directory: /
|
5
|
+
schedule:
|
6
|
+
interval: daily
|
7
|
+
labels:
|
8
|
+
- dependency
|
9
|
+
versioning-strategy: increase-if-necessary
|
10
|
+
- package-ecosystem: github-actions
|
11
|
+
directory: /
|
12
|
+
schedule:
|
13
|
+
interval: daily
|
14
|
+
labels:
|
15
|
+
- dependency
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: ci
|
2
|
+
'on':
|
3
|
+
- push
|
4
|
+
- pull_request
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Node ${{ matrix.node }} / ${{ matrix.os }}
|
8
|
+
runs-on: ${{ matrix.os }}
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
os:
|
13
|
+
- ubuntu-latest
|
14
|
+
node:
|
15
|
+
- '14'
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: actions/setup-node@v2
|
19
|
+
with:
|
20
|
+
node-version: ${{ matrix.node }}
|
21
|
+
- run: npm install
|
22
|
+
- run: npm run build --if-present
|
23
|
+
- run: npm test
|
package/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# cross-zip [![
|
1
|
+
# cross-zip [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
|
2
2
|
|
3
|
-
[
|
4
|
-
[
|
3
|
+
[ci-image]: https://img.shields.io/github/workflow/status/feross/cross-zip/ci/master
|
4
|
+
[ci-url]: https://github.com/feross/cross-zip/actions
|
5
5
|
[npm-image]: https://img.shields.io/npm/v/cross-zip.svg
|
6
6
|
[npm-url]: https://npmjs.org/package/cross-zip
|
7
7
|
[downloads-image]: https://img.shields.io/npm/dm/cross-zip.svg
|
package/index.js
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
/*! cross-zip. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
2
2
|
module.exports = {
|
3
|
-
zip
|
4
|
-
zipSync
|
5
|
-
unzip
|
6
|
-
unzipSync
|
3
|
+
zip,
|
4
|
+
zipSync,
|
5
|
+
unzip,
|
6
|
+
unzipSync
|
7
7
|
}
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
var rimraf = require('rimraf')
|
9
|
+
const cp = require('child_process')
|
10
|
+
const fs = require('fs')
|
11
|
+
const os = require('os')
|
12
|
+
const path = require('path')
|
14
13
|
|
15
14
|
function zip (inPath, outPath, cb) {
|
16
15
|
if (!cb) cb = function () {}
|
@@ -32,7 +31,7 @@ function zip (inPath, outPath, cb) {
|
|
32
31
|
function copyToTemp () {
|
33
32
|
fs.readFile(inPath, function (err, inFile) {
|
34
33
|
if (err) return cb(err)
|
35
|
-
|
34
|
+
const tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now())
|
36
35
|
fs.mkdir(tmpPath, function (err) {
|
37
36
|
if (err) return cb(err)
|
38
37
|
fs.writeFile(path.join(tmpPath, path.basename(inPath)), inFile, function (err) {
|
@@ -47,14 +46,14 @@ function zip (inPath, outPath, cb) {
|
|
47
46
|
// Windows zip command does not overwrite existing files. So do it manually first.
|
48
47
|
function doZip () {
|
49
48
|
if (process.platform === 'win32') {
|
50
|
-
|
49
|
+
fs.rmdir(outPath, { recursive: true, maxRetries: 3 }, doZip2)
|
51
50
|
} else {
|
52
51
|
doZip2()
|
53
52
|
}
|
54
53
|
}
|
55
54
|
|
56
55
|
function doZip2 () {
|
57
|
-
|
56
|
+
const opts = {
|
58
57
|
cwd: path.dirname(inPath),
|
59
58
|
maxBuffer: Infinity
|
60
59
|
}
|
@@ -67,15 +66,15 @@ function zip (inPath, outPath, cb) {
|
|
67
66
|
function zipSync (inPath, outPath) {
|
68
67
|
if (process.platform === 'win32') {
|
69
68
|
if (fs.statSync(inPath).isFile()) {
|
70
|
-
|
71
|
-
|
69
|
+
const inFile = fs.readFileSync(inPath)
|
70
|
+
const tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now())
|
72
71
|
fs.mkdirSync(tmpPath)
|
73
72
|
fs.writeFileSync(path.join(tmpPath, path.basename(inPath)), inFile)
|
74
73
|
inPath = tmpPath
|
75
74
|
}
|
76
|
-
|
75
|
+
fs.rmdirSync(outPath, { recursive: true, maxRetries: 3 })
|
77
76
|
}
|
78
|
-
|
77
|
+
const opts = {
|
79
78
|
cwd: path.dirname(inPath),
|
80
79
|
maxBuffer: Infinity
|
81
80
|
}
|
@@ -84,7 +83,7 @@ function zipSync (inPath, outPath) {
|
|
84
83
|
|
85
84
|
function unzip (inPath, outPath, cb) {
|
86
85
|
if (!cb) cb = function () {}
|
87
|
-
|
86
|
+
const opts = {
|
88
87
|
maxBuffer: Infinity
|
89
88
|
}
|
90
89
|
cp.execFile(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts, function (err) {
|
@@ -93,7 +92,7 @@ function unzip (inPath, outPath, cb) {
|
|
93
92
|
}
|
94
93
|
|
95
94
|
function unzipSync (inPath, outPath) {
|
96
|
-
|
95
|
+
const opts = {
|
97
96
|
maxBuffer: Infinity
|
98
97
|
}
|
99
98
|
cp.execFileSync(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts)
|
@@ -129,7 +128,7 @@ function getZipArgs (inPath, outPath) {
|
|
129
128
|
'-myOutPath', quotePath(outPath)
|
130
129
|
]
|
131
130
|
} else {
|
132
|
-
|
131
|
+
const fileName = path.basename(inPath)
|
133
132
|
return ['-r', '-y', outPath, fileName]
|
134
133
|
}
|
135
134
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "cross-zip",
|
3
3
|
"description": "Cross-platform .zip file creation",
|
4
|
-
"version": "
|
4
|
+
"version": "4.0.1",
|
5
5
|
"author": {
|
6
6
|
"name": "Feross Aboukhadijeh",
|
7
7
|
"email": "feross@feross.org",
|
@@ -34,8 +34,8 @@
|
|
34
34
|
"scripts": {
|
35
35
|
"test": "standard && tape test/*.js"
|
36
36
|
},
|
37
|
-
"
|
38
|
-
"
|
37
|
+
"engines": {
|
38
|
+
"node": ">=12.10"
|
39
39
|
},
|
40
40
|
"funding": [
|
41
41
|
{
|
package/test/unzip.js
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
var zip = require('../')
|
1
|
+
const fs = require('fs')
|
2
|
+
const path = require('path')
|
3
|
+
const test = require('tape')
|
4
|
+
const zip = require('../')
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
const filePath = path.join(__dirname, 'content', 'file.txt')
|
7
|
+
const fileZipPath = path.join(__dirname, 'content', 'file.txt.zip')
|
8
|
+
const tmpPath = path.join(__dirname, 'tmp')
|
10
9
|
|
11
10
|
fs.mkdirSync(tmpPath, { recursive: true })
|
12
11
|
|
13
12
|
test('unzipSync', function (t) {
|
14
|
-
|
15
|
-
|
13
|
+
const tmpFilePath = path.join(tmpPath, 'file.txt')
|
14
|
+
fs.rmSync(tmpFilePath, { recursive: true, force: true })
|
16
15
|
zip.unzipSync(fileZipPath, tmpPath)
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
const tmpFile = fs.readFileSync(tmpFilePath)
|
18
|
+
const file = fs.readFileSync(filePath)
|
20
19
|
|
21
20
|
t.deepEqual(tmpFile, file)
|
22
21
|
t.end()
|
@@ -25,15 +24,15 @@ test('unzipSync', function (t) {
|
|
25
24
|
test('unzip', function (t) {
|
26
25
|
t.plan(3)
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
const tmpFilePath = path.join(tmpPath, 'file.txt')
|
28
|
+
fs.rm(tmpFilePath, { recursive: true }, function (err) {
|
30
29
|
t.error(err)
|
31
30
|
|
32
31
|
zip.unzip(fileZipPath, tmpPath, function (err) {
|
33
32
|
t.error(err)
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
const tmpFile = fs.readFileSync(tmpFilePath)
|
35
|
+
const file = fs.readFileSync(filePath)
|
37
36
|
|
38
37
|
t.deepEqual(tmpFile, file)
|
39
38
|
})
|
@@ -43,20 +42,24 @@ test('unzip', function (t) {
|
|
43
42
|
test('unzip from a folder with a space in it', function (t) {
|
44
43
|
t.plan(4)
|
45
44
|
|
46
|
-
|
45
|
+
const zipSpacePath = path.join(
|
46
|
+
tmpPath,
|
47
|
+
'folder space',
|
48
|
+
path.basename(fileZipPath)
|
49
|
+
)
|
47
50
|
fs.mkdirSync(path.dirname(zipSpacePath), { recursive: true })
|
48
51
|
fs.copyFileSync(fileZipPath, zipSpacePath)
|
49
52
|
|
50
|
-
|
51
|
-
|
53
|
+
const tmpFilePath = path.join(tmpPath, 'file.txt')
|
54
|
+
fs.rm(tmpFilePath, { recursive: true }, function (err) {
|
52
55
|
t.error(err)
|
53
56
|
|
54
57
|
zip.unzip(zipSpacePath, tmpPath, function (err) {
|
55
58
|
t.error(err)
|
56
59
|
|
57
60
|
t.ok(fs.existsSync(tmpFilePath), 'extracted file should exist')
|
58
|
-
|
59
|
-
|
61
|
+
const tmpFile = fs.readFileSync(tmpFilePath)
|
62
|
+
const file = fs.readFileSync(filePath)
|
60
63
|
|
61
64
|
t.deepEqual(tmpFile, file)
|
62
65
|
})
|
package/test/zip.js
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
var zip = require('../')
|
1
|
+
const fs = require('fs')
|
2
|
+
const path = require('path')
|
3
|
+
const test = require('tape')
|
4
|
+
const zip = require('../')
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
const filePath = path.join(__dirname, 'content', 'file.txt')
|
7
|
+
const tmpPath = path.join(__dirname, 'tmp')
|
9
8
|
|
10
9
|
fs.mkdirSync(tmpPath, { recursive: true })
|
11
10
|
|
12
11
|
test('zipSync', function (t) {
|
13
|
-
|
12
|
+
const tmpFileZipPath = path.join(tmpPath, 'file.zip')
|
14
13
|
zip.zipSync(filePath, tmpFileZipPath)
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
const tmpFilePath = path.join(tmpPath, 'file.txt')
|
16
|
+
fs.rmSync(tmpFilePath, { recursive: true, force: true })
|
18
17
|
zip.unzipSync(tmpFileZipPath, tmpPath)
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
const tmpFile = fs.readFileSync(tmpFilePath)
|
20
|
+
const file = fs.readFileSync(filePath)
|
22
21
|
|
23
22
|
t.deepEqual(tmpFile, file)
|
24
23
|
t.end()
|
@@ -27,19 +26,19 @@ test('zipSync', function (t) {
|
|
27
26
|
test('zip', function (t) {
|
28
27
|
t.plan(4)
|
29
28
|
|
30
|
-
|
29
|
+
const tmpFileZipPath = path.join(tmpPath, 'file.zip')
|
31
30
|
zip.zip(filePath, tmpFileZipPath, function (err) {
|
32
31
|
t.error(err)
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
const tmpFilePath = path.join(tmpPath, 'file.txt')
|
34
|
+
fs.rm(tmpFilePath, { recursive: true }, function (err) {
|
36
35
|
t.error(err)
|
37
36
|
|
38
37
|
zip.unzip(tmpFileZipPath, tmpPath, function (err) {
|
39
38
|
t.error(err)
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
const tmpFile = fs.readFileSync(tmpFilePath)
|
41
|
+
const file = fs.readFileSync(filePath)
|
43
42
|
|
44
43
|
t.deepEqual(tmpFile, file)
|
45
44
|
})
|