diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..aaecad5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "eslint:recommended", + "env": { + "node": true + } +} \ No newline at end of file diff --git a/index.js b/index.js index 61b8c81..21ae1de 100644 --- a/index.js +++ b/index.js @@ -9,17 +9,24 @@ function zipFolder(srcFolder, zipFilePath, callback) { callback(); }); + zipArchive.on('warning', function(err) { + if (err.code === 'ENOENT') { + // log warning + } else { + // throw error + throw err; + } + }); + + zipArchive.on('error', function(err) { + throw err; + }); + zipArchive.pipe(output); - zipArchive.bulk([ - { cwd: srcFolder, src: ['**/*'], expand: true } - ]); + zipArchive.directory(srcFolder, false); - zipArchive.finalize(function(err, bytes) { - if(err) { - callback(err); - } - }); + zipArchive.finalize(); } module.exports = zipFolder; diff --git a/package.json b/package.json index 2de8ef7..14501fc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "homepage": "https://github.com/sole/node-zip-folder", "dependencies": { - "archiver": "^0.11.0" + "archiver": "^2.1.1" }, "devDependencies": { "nodeunit": "^0.9.0", diff --git a/tests.js b/tests.js index 441173e..741cb9c 100644 --- a/tests.js +++ b/tests.js @@ -6,7 +6,7 @@ var zipFolder = require('./index'); var txtFileName = 'file.txt'; var txtFileContents = 'this is a text file'; -var zipFileName = 'archive.zip'; +// var zipFileName = 'archive.zip'; function emptyDirectory(dirName) { var dirFiles = fs.readdirSync(dirName); @@ -14,7 +14,7 @@ function emptyDirectory(dirName) { var entryPath = path.join(dirName, f); var fileStats = fs.statSync(entryPath); if(fileStats.isFile()) { - fs.unlink(entryPath); + fs.unlinkSync(entryPath); } else { emptyDirectory(entryPath); } @@ -45,12 +45,12 @@ module.exports = { tearDown: function(callback) { emptyDirectory(this.tmpSrcDir.path); - this.tmpSrcDir.rmdir(); + this.tmpSrcDir.rmdirSync(); emptyDirectory(this.tmpZipExtractionDir.path); - this.tmpZipExtractionDir.rmdir(); + this.tmpZipExtractionDir.rmdirSync(); - this.tmpZipFile.unlink(); + this.tmpZipFile.unlinkSync(); callback(); },