Skip to content

Commit 3dd19cb

Browse files
committed
do headless zip on exit
1 parent a9ebf95 commit 3dd19cb

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

headless_zip.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,27 @@ module.exports.headlessZip = function headlessZip(dirToZip) {
8080
}
8181

8282
var zip = new JSZip();
83-
fs.readdir(dirToZip, function(error, files) {
84-
if (error) {
85-
onError(error)
86-
return
87-
}
88-
for (var i = 0, len = files.length; i < len; i++) {
89-
zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), {compression : "DEFLATE"})
83+
var files = fs.readdirSync(dirToZip)
84+
for (var i = 0, len = files.length; i < len; i++) {
85+
zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), {compression : "DEFLATE"})
86+
}
87+
fs.writeFileSync(outputFileName, zip.generate({type:"nodebuffer", compression:'DEFLATE'}));
88+
deleteDir(dirToZip)
89+
}
90+
91+
module.exports.tryZipOnExit = function tryZipOnExit() {
92+
var outputDir = dirToWriteTo;
93+
if(!outputDir) {
94+
ouputDir = process.cwd().toString()
95+
}
96+
var files = fs.readdirSync(outputDir);
97+
// Search for temporary output directory using pattern matching
98+
for (var i = 0, len = files.length; i < len; i++) {
99+
if(/tmp_(\w+)/.test(files[i].toString())) {
100+
var dirToZip = path.join(outputDir, files[i])
101+
this.headlessZip(dirToZip)
102+
return;
90103
}
91-
92-
zip.generateNodeStream({type:'nodebuffer',streamFiles:true})
93-
.pipe(fs.createWriteStream(outputFileName))
94-
.on('finish', function () {
95-
deleteDir(dirToZip)
96-
})
97-
})
98-
}
104+
}
105+
}
106+

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ module.exports.start = function start () {
301301
var am = this;
302302
agent.start();
303303
process.on('exit', function () {
304+
var headlessMode = agent.getOption('com.ibm.diagnostics.healthcenter.headless');
304305
am.stop();
306+
if(headlessMode == 'on') {
307+
headlessZip.tryZipOnExit();
308+
}
305309
});
306310
}
307311

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dependencies": {
99
"nan": "2.x",
1010
"tar": "2.x",
11-
"jszip": "3.0.x"
11+
"jszip": "2.5.x"
1212
},
1313
"bundleDependencies": [
1414
"tar"

0 commit comments

Comments
 (0)