Comparing version 2.0.1 to 2.1.0
76
index.js
@@ -9,11 +9,65 @@ module.exports = { | ||
var cp = require('child_process') | ||
var fs = require('fs') | ||
var os = require('os') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
function zip (inPath, outPath, cb) { | ||
cp.exec(getZipCommand(inPath, outPath), function (err) { | ||
cb(err) | ||
}) | ||
if (process.platform === 'win32') { | ||
fs.stat(inPath, function (err, stats) { | ||
if (err) return cb(err) | ||
if (stats.isFile()) { | ||
copyToTemp() | ||
} else { | ||
doZip() | ||
} | ||
}) | ||
} else { | ||
doZip() | ||
} | ||
// Windows zip command cannot zip files, only directories. So move the file into | ||
// a temporary directory before zipping. | ||
function copyToTemp () { | ||
fs.readFile(inPath, function (err, inFile) { | ||
if (err) return cb(err) | ||
var tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) | ||
fs.mkdir(tmpPath, function (err) { | ||
if (err) return cb(err) | ||
fs.writeFile(path.join(tmpPath, path.basename(inPath)), inFile, function (err) { | ||
if (err) return cb(err) | ||
inPath = tmpPath | ||
doZip() | ||
}) | ||
}) | ||
}) | ||
} | ||
// Windows zip command does not overwrite existing files. So do it manually first. | ||
function doZip () { | ||
if (process.platform === 'win32') { | ||
rimraf(outPath, doZip2) | ||
} else { | ||
doZip2() | ||
} | ||
} | ||
function doZip2 () { | ||
cp.exec(getZipCommand(inPath, outPath), function (err) { | ||
cb(err) | ||
}) | ||
} | ||
} | ||
function zipSync (inPath, outPath) { | ||
if (process.platform === 'win32') { | ||
if (fs.statSync(inPath).isFile()) { | ||
var inFile = fs.readFileSync(inPath) | ||
var tmpPath = path.join(os.tmpdir(), 'cross-zip-' + Date.now()) | ||
fs.mkdirSync(tmpPath) | ||
fs.writeFileSync(path.join(tmpPath, path.basename(inPath)), inFile) | ||
inPath = tmpPath | ||
} | ||
rimraf.sync(outPath) | ||
} | ||
cp.execSync(getZipCommand(inPath, outPath)) | ||
@@ -24,11 +78,7 @@ } | ||
if (process.platform === 'win32') { | ||
return ( | ||
'powershell.exe -nologo -noprofile -command "& { ' + | ||
'Add-Type -A \'System.IO.Compression.FileSystem\'; ' + | ||
`[IO.Compression.ZipFile]::CreateFromDirectory('${inPath}', '${outPath}'); }"` | ||
) | ||
return `powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('${inPath}', '${outPath}'); }"` | ||
} else { | ||
var dirPath = path.dirname(inPath) | ||
var fileName = path.basename(inPath) | ||
return `cd ${dirPath} && zip -r -y ${outPath} ${fileName}` | ||
return `cd ${dirPath} && zip -r -y ${JSON.stringify(outPath)} ${JSON.stringify(fileName)}` | ||
} | ||
@@ -49,10 +99,6 @@ } | ||
if (process.platform === 'win32') { | ||
return ( | ||
'powershell.exe -nologo -noprofile -command "& { ' + | ||
'Add-Type -A \'System.IO.Compression.FileSystem\'; ' + | ||
`[IO.Compression.ZipFile]::ExtractToDirectory('${inPath}', '${outPath}'); }"` | ||
) | ||
return `powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${inPath}', '${outPath}'); }"` | ||
} else { | ||
return `unzip -o ${inPath} -d ${outPath}` | ||
return `unzip -o ${JSON.stringify(inPath)} -d ${JSON.stringify(outPath)}` | ||
} | ||
} |
{ | ||
"name": "cross-zip", | ||
"description": "Cross-platform .zip file creation", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -15,3 +15,3 @@ "name": "Feross Aboukhadijeh", | ||
"mkdirp": "^0.5.1", | ||
"standard": "^6.0.8", | ||
"standard": "^7.0.0", | ||
"tape": "^4.0.0" | ||
@@ -21,10 +21,10 @@ }, | ||
"keywords": [ | ||
"zip", | ||
"ZIP", | ||
"cross platform", | ||
"cross-platform", | ||
"linux", | ||
"mac", | ||
"os x", | ||
"windows", | ||
"os x", | ||
"mac", | ||
"linux", | ||
"cross platform", | ||
"cross-platform" | ||
"zip" | ||
], | ||
@@ -39,3 +39,6 @@ "license": "MIT", | ||
"test": "standard && tape test/*.js" | ||
}, | ||
"dependencies": { | ||
"rimraf": "^2.5.2" | ||
} | ||
} |
var fs = require('fs') | ||
var mkdirp = require('mkdirp') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var test = require('tape') | ||
@@ -14,5 +15,6 @@ var zip = require('../') | ||
test('unzipSync', function (t) { | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
rimraf.sync(tmpFilePath) | ||
zip.unzipSync(fileZipPath, tmpPath) | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
@@ -26,13 +28,17 @@ var file = fs.readFileSync(filePath) | ||
test('unzip', function (t) { | ||
t.plan(2) | ||
t.plan(3) | ||
zip.unzip(fileZipPath, tmpPath, function (err) { | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
rimraf(tmpFilePath, function (err) { | ||
t.error(err) | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
var file = fs.readFileSync(filePath) | ||
zip.unzip(fileZipPath, tmpPath, function (err) { | ||
t.error(err) | ||
t.deepEqual(tmpFile, file) | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
var file = fs.readFileSync(filePath) | ||
t.deepEqual(tmpFile, file) | ||
}) | ||
}) | ||
}) |
var fs = require('fs') | ||
var mkdirp = require('mkdirp') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var test = require('tape') | ||
@@ -13,7 +14,9 @@ var zip = require('../') | ||
test('zipSync', function (t) { | ||
var tmpFileZipPath = path.join(tmpPath, 'file.zip.txt') | ||
var tmpFileZipPath = path.join(tmpPath, 'file.zip') | ||
zip.zipSync(filePath, tmpFileZipPath) | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
rimraf.sync(tmpFilePath) | ||
zip.unzipSync(tmpFileZipPath, tmpPath) | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
@@ -27,18 +30,22 @@ var file = fs.readFileSync(filePath) | ||
test('zip', function (t) { | ||
t.plan(3) | ||
t.plan(4) | ||
var tmpFileZipPath = path.join(tmpPath, 'file.zip.txt') | ||
var tmpFileZipPath = path.join(tmpPath, 'file.zip') | ||
zip.zip(filePath, tmpFileZipPath, function (err) { | ||
t.error(err) | ||
zip.unzip(tmpFileZipPath, tmpPath, function (err) { | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
rimraf(tmpFilePath, function (err) { | ||
t.error(err) | ||
var tmpFilePath = path.join(tmpPath, 'file.txt') | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
var file = fs.readFileSync(filePath) | ||
zip.unzip(tmpFileZipPath, tmpPath, function (err) { | ||
t.error(err) | ||
t.deepEqual(tmpFile, file) | ||
var tmpFile = fs.readFileSync(tmpFilePath) | ||
var file = fs.readFileSync(filePath) | ||
t.deepEqual(tmpFile, file) | ||
}) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8393
160
1
10
3
+ Addedrimraf@^2.5.2
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)