diff --git a/.eslintrc b/.eslintrc index 9f9ba6b..f96d009 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,8 @@ { "extends": "strongloop", "env": { - "node": true + "node": true, + "es6": true }, "parserOptions": { "ecmaVersion": 6 }, "rules": { diff --git a/headless_zip.js b/headless_zip.js index dfb4903..9dab196 100644 --- a/headless_zip.js +++ b/headless_zip.js @@ -16,6 +16,7 @@ 'use strict'; var fs = require('fs'); +var fsPromise = require('fs/promises'); var path = require('path'); var JSZip = require('jszip'); @@ -85,14 +86,19 @@ module.exports.headlessZip = function headlessZip(dirToZip) { if (fs.existsSync(dirToZip)) { var zip = new JSZip(); - var files = fs.readdirSync(dirToZip); - for (var i = 0, len = files.length; i < len; i++) { - zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), { - compression: 'DEFLATE', - }); - } - fs.writeFileSync(outputFileName, zip.generate({ type: 'nodebuffer', compression: 'DEFLATE' })); - deleteDir(dirToZip); + + fsPromise.readdir(dirToZip) + .then(files => { + let getFileAndContents = file => fsPromise.readFile(path.join(dirToZip, file)) + .then(contents => { return { file, contents }; }); + return Promise.all(files.map(getFileAndContents)); + }) + .then(files => { + files.forEach(({file, contents}) => zip.file(file, contents, {compression: 'DEFLATE'})); + return zip.generateAsync({type: 'nodebuffer', compression: 'DEFLATE'}); + }) + .then(buffer => fsPromise.writeFile(outputFileName, buffer)) + .then(() => { deleteDir(dirToZip); }); } }; diff --git a/package.json b/package.json index d7c5c81..dedca4a 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ }, "description": "Node Application Metrics", "dependencies": { + "ibmapm-embed": ">=19.9.0", + "jszip": "^3.7.1", "nan": "2.x", "node-gyp": "5.x", - "tar": "4.x", "semver": "^5.3.0", - "jszip": "2.5.x", - "ibmapm-embed": ">=19.9.0" + "tar": "4.x" }, "devDependencies": { "codecov": "^3.1.0",