Skip to content

Commit 3e389c9

Browse files
committed
Use jszip for headless zip instead of zlib
1 parent 749a2ed commit 3e389c9

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

headless_zip.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
* limitations under the License.
1515
*******************************************************************************/
1616

17-
var fstream = require('fstream')
18-
var tar = require('tar')
19-
var zlib = require('zlib')
2017
var fs = require('fs')
2118
var path = require('path')
19+
var JSZip = require("jszip");
2220

2321
var dirToWriteTo;
2422

@@ -43,7 +41,7 @@ module.exports.setHeadlessOutputDir = function setHeadlessOutputDir(dir) {
4341

4442
function timestamp() {
4543
var date = new Date(Date.now())
46-
var timestamp = pad(date.getDate().toString()) + pad(date.getMonth().toString()) + date.getFullYear().toString().substr(2,3) + '_'
44+
var timestamp = pad(date.getDate().toString()) + pad((date.getMonth() + 1).toString()) + date.getFullYear().toString().substr(2,3) + '_'
4745
+ pad(date.getHours().toString()) + pad(date.getMinutes().toString()) + pad(date.getSeconds().toString()) + '_'
4846
+ process.pid
4947
return timestamp
@@ -65,19 +63,20 @@ module.exports.headlessZip = function headlessZip(dirToZip) {
6563
outputFileName = 'nodeappmetrics' + timestamp() + '.hcd'
6664
}
6765

68-
var packer = tar.Pack({ fromBase: true })
69-
.on('error', onError)
70-
var zipper = zlib.Gzip()
71-
var writer = fstream.Writer({'path': outputFileName})
72-
.on('error', onError)
73-
.on('close', function() {
74-
deleteDir(dirToZip)
75-
})
76-
77-
fstream.Reader({'path': dirToZip, 'type': 'Directory'})
78-
.on('error', onError)
79-
.pipe(packer)
80-
.pipe(zipper)
81-
.pipe(writer)
66+
var zip = new JSZip();
67+
fs.readdir(dirToZip, function(error, files) {
68+
if (error) {
69+
onError(error)
70+
return
71+
}
72+
for (var i = 0, len = files.length; i < len; i++) {
73+
zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), {compression : "DEFLATE"})
74+
}
8275

76+
zip.generateNodeStream({type:'nodebuffer',streamFiles:true})
77+
.pipe(fs.createWriteStream(outputFileName))
78+
.on('finish', function () {
79+
deleteDir(dirToZip)
80+
})
81+
})
8382
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"heapdump": "0.x",
1010
"nan": "2.x",
1111
"nodereport": "1.x",
12-
"tar": "2.x"
12+
"tar": "2.x",
13+
"jszip": "3.0.x"
1314
},
1415
"bundleDependencies": [
1516
"tar"

0 commit comments

Comments
 (0)