cross-zip 2.1.4 → 3.1.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/.travis.yml CHANGED
@@ -1,3 +1,9 @@
1
1
  language: node_js
2
2
  node_js:
3
- - 'node'
3
+ - lts/*
4
+ os:
5
+ - linux
6
+ - osx
7
+ - windows
8
+ git:
9
+ autocrlf: input
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # cross-zip [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]
1
+ # cross-zip [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
2
2
 
3
3
  [travis-image]: https://img.shields.io/travis/feross/cross-zip/master.svg
4
4
  [travis-url]: https://travis-ci.org/feross/cross-zip
@@ -6,6 +6,8 @@
6
6
  [npm-url]: https://npmjs.org/package/cross-zip
7
7
  [downloads-image]: https://img.shields.io/npm/dm/cross-zip.svg
8
8
  [downloads-url]: https://npmjs.org/package/cross-zip
9
+ [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
10
+ [standard-url]: https://standardjs.com
9
11
 
10
12
  ### Cross-platform .zip file creation
11
13
 
@@ -59,6 +61,10 @@ On Windows 7 or earlier, you will need to install these manually in order for
59
61
 
60
62
  - [Stack Overflow - zipping from command line in Windows](https://stackoverflow.com/questions/17546016/how-can-you-zip-or-unzip-from-the-command-prompt-using-only-windows-built-in-ca)
61
63
 
64
+ ## related
65
+
66
+ - [cross-zip-cli](https://github.com/jprichardson/cross-zip-cli): CLI version of cross-zip.
67
+
62
68
  ## license
63
69
 
64
70
  MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /*! cross-zip. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
1
2
  module.exports = {
2
3
  zip: zip,
3
4
  zipSync: zipSync,
@@ -53,7 +54,11 @@ function zip (inPath, outPath, cb) {
53
54
  }
54
55
 
55
56
  function doZip2 () {
56
- cp.exec(getZipCommand(inPath, outPath), function (err) {
57
+ var opts = {
58
+ cwd: path.dirname(inPath),
59
+ maxBuffer: Infinity
60
+ }
61
+ cp.execFile(getZipCommand(), getZipArgs(inPath, outPath), opts, function (err) {
57
62
  cb(err)
58
63
  })
59
64
  }
@@ -70,34 +75,75 @@ function zipSync (inPath, outPath) {
70
75
  }
71
76
  rimraf.sync(outPath)
72
77
  }
73
- cp.execSync(getZipCommand(inPath, outPath))
74
- }
75
-
76
- function getZipCommand (inPath, outPath) {
77
- if (process.platform === 'win32') {
78
- return `powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('${inPath}', '${outPath}'); }"`
79
- } else {
80
- var dirPath = path.dirname(inPath)
81
- var fileName = path.basename(inPath)
82
- return `cd ${JSON.stringify(dirPath)} && zip -r -y ${JSON.stringify(outPath)} ${JSON.stringify(fileName)}`
78
+ var opts = {
79
+ cwd: path.dirname(inPath),
80
+ maxBuffer: Infinity
83
81
  }
82
+ cp.execFileSync(getZipCommand(), getZipArgs(inPath, outPath), opts)
84
83
  }
85
84
 
86
85
  function unzip (inPath, outPath, cb) {
87
86
  if (!cb) cb = function () {}
88
- cp.exec(getUnzipCommand(inPath, outPath), function (err) {
87
+ var opts = {
88
+ maxBuffer: Infinity
89
+ }
90
+ cp.execFile(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts, function (err) {
89
91
  cb(err)
90
92
  })
91
93
  }
92
94
 
93
95
  function unzipSync (inPath, outPath) {
94
- cp.execSync(getUnzipCommand(inPath, outPath))
96
+ var opts = {
97
+ maxBuffer: Infinity
98
+ }
99
+ cp.execFileSync(getUnzipCommand(), getUnzipArgs(inPath, outPath), opts)
100
+ }
101
+
102
+ function getZipCommand () {
103
+ if (process.platform === 'win32') {
104
+ return 'powershell.exe'
105
+ } else {
106
+ return 'zip'
107
+ }
108
+ }
109
+
110
+ function getUnzipCommand () {
111
+ if (process.platform === 'win32') {
112
+ return 'powershell.exe'
113
+ } else {
114
+ return 'unzip'
115
+ }
116
+ }
117
+
118
+ function quotePath (pathToTransform) {
119
+ return '"' + pathToTransform + '"'
120
+ }
121
+
122
+ function getZipArgs (inPath, outPath) {
123
+ if (process.platform === 'win32') {
124
+ return [
125
+ '-nologo',
126
+ '-noprofile',
127
+ '-command', '& { param([String]$myInPath, [String]$myOutPath); Add-Type -A "System.IO.Compression.FileSystem"; [IO.Compression.ZipFile]::CreateFromDirectory($myInPath, $myOutPath); exit !$? }',
128
+ '-myInPath', quotePath(inPath),
129
+ '-myOutPath', quotePath(outPath)
130
+ ]
131
+ } else {
132
+ var fileName = path.basename(inPath)
133
+ return ['-r', '-y', outPath, fileName]
134
+ }
95
135
  }
96
136
 
97
- function getUnzipCommand (inPath, outPath) {
137
+ function getUnzipArgs (inPath, outPath) {
98
138
  if (process.platform === 'win32') {
99
- return `powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${inPath}', '${outPath}'); }"`
139
+ return [
140
+ '-nologo',
141
+ '-noprofile',
142
+ '-command', '& { param([String]$myInPath, [String]$myOutPath); Add-Type -A "System.IO.Compression.FileSystem"; [IO.Compression.ZipFile]::ExtractToDirectory($myInPath, $myOutPath); exit !$? }',
143
+ '-myInPath', quotePath(inPath),
144
+ '-myOutPath', quotePath(outPath)
145
+ ]
100
146
  } else {
101
- return `unzip -o ${JSON.stringify(inPath)} -d ${JSON.stringify(outPath)}`
147
+ return ['-o', inPath, '-d', outPath]
102
148
  }
103
149
  }
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "cross-zip",
3
3
  "description": "Cross-platform .zip file creation",
4
- "version": "2.1.4",
4
+ "version": "3.1.0",
5
5
  "author": {
6
6
  "name": "Feross Aboukhadijeh",
7
7
  "email": "feross@feross.org",
8
- "url": "http://feross.org/"
8
+ "url": "https://feross.org"
9
9
  },
10
10
  "bugs": {
11
11
  "url": "https://github.com/feross/cross-zip/issues"
12
12
  },
13
13
  "devDependencies": {
14
- "mkdirp": "^0.5.1",
15
- "standard": "^7.0.0",
16
- "tape": "^4.0.0"
14
+ "standard": "*",
15
+ "tape": "^5.0.0"
17
16
  },
18
17
  "homepage": "https://github.com/feross/cross-zip",
19
18
  "keywords": [
@@ -36,6 +35,20 @@
36
35
  "test": "standard && tape test/*.js"
37
36
  },
38
37
  "dependencies": {
39
- "rimraf": "^2.5.2"
40
- }
38
+ "rimraf": "^3.0.0"
39
+ },
40
+ "funding": [
41
+ {
42
+ "type": "github",
43
+ "url": "https://github.com/sponsors/feross"
44
+ },
45
+ {
46
+ "type": "patreon",
47
+ "url": "https://www.patreon.com/feross"
48
+ },
49
+ {
50
+ "type": "consulting",
51
+ "url": "https://feross.org/support"
52
+ }
53
+ ]
41
54
  }
package/test/unzip.js CHANGED
@@ -1,5 +1,4 @@
1
1
  var fs = require('fs')
2
- var mkdirp = require('mkdirp')
3
2
  var path = require('path')
4
3
  var rimraf = require('rimraf')
5
4
  var test = require('tape')
@@ -9,7 +8,7 @@ var filePath = path.join(__dirname, 'content', 'file.txt')
9
8
  var fileZipPath = path.join(__dirname, 'content', 'file.txt.zip')
10
9
  var tmpPath = path.join(__dirname, 'tmp')
11
10
 
12
- mkdirp.sync(tmpPath)
11
+ fs.mkdirSync(tmpPath, { recursive: true })
13
12
 
14
13
  test('unzipSync', function (t) {
15
14
  var tmpFilePath = path.join(tmpPath, 'file.txt')
@@ -40,3 +39,26 @@ test('unzip', function (t) {
40
39
  })
41
40
  })
42
41
  })
42
+
43
+ test('unzip from a folder with a space in it', function (t) {
44
+ t.plan(4)
45
+
46
+ var zipSpacePath = path.join(tmpPath, 'folder space', path.basename(fileZipPath))
47
+ fs.mkdirSync(path.dirname(zipSpacePath), { recursive: true })
48
+ fs.copyFileSync(fileZipPath, zipSpacePath)
49
+
50
+ var tmpFilePath = path.join(tmpPath, 'file.txt')
51
+ rimraf(tmpFilePath, function (err) {
52
+ t.error(err)
53
+
54
+ zip.unzip(zipSpacePath, tmpPath, function (err) {
55
+ t.error(err)
56
+
57
+ t.ok(fs.existsSync(tmpFilePath), 'extracted file should exist')
58
+ var tmpFile = fs.readFileSync(tmpFilePath)
59
+ var file = fs.readFileSync(filePath)
60
+
61
+ t.deepEqual(tmpFile, file)
62
+ })
63
+ })
64
+ })
package/test/zip.js CHANGED
@@ -1,5 +1,4 @@
1
1
  var fs = require('fs')
2
- var mkdirp = require('mkdirp')
3
2
  var path = require('path')
4
3
  var rimraf = require('rimraf')
5
4
  var test = require('tape')
@@ -8,7 +7,7 @@ var zip = require('../')
8
7
  var filePath = path.join(__dirname, 'content', 'file.txt')
9
8
  var tmpPath = path.join(__dirname, 'tmp')
10
9
 
11
- mkdirp.sync(tmpPath)
10
+ fs.mkdirSync(tmpPath, { recursive: true })
12
11
 
13
12
  test('zipSync', function (t) {
14
13
  var tmpFileZipPath = path.join(tmpPath, 'file.zip')
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules/
2
- test/tmp