-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip_util.js
47 lines (42 loc) · 1.52 KB
/
zip_util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var util = require('util');
var exec = require('child_process').exec;
var PACK_EXCLUSION_GLOBS = ['..', '.', '*~', '#*#', '*.log', '.git/*']
var ZipUtil = module.exports = {
pack: function(dir, zipfile, callback) {
var excludes = PACK_EXCLUSION_GLOBS.map(function(e) { return '\\' + e; }).join(' ');
var packCommand = 'zip -y -q -r "' + zipfile + '" . -x ' + excludes + ' 2> /dev/null';
exec(packCommand, { cwd: dir },
function (error, stdout, stderr) {
if (error)
console.error('exec error: ' + error);
callback(error);
});
// Do NodeJS version if the native version failed
},
unpack: function(file, dest, callback) {
var excludes = PACK_EXCLUSION_GLOBS.map(function(e) { return '\\' + e; }).join(' ');
var unpackCommand = 'unzip -q "' + file + '" -d "' + dest + '" 2> /dev/null';
exec(unpackCommand,
function (error, stdout, stderr) {
if (error)
console.error('exec error: ' + error);
callback(error);
});
// Do NodeJS version if the native version failed
},
entry_lines: function(file, callback) {
var contents = null;
var entryCommand = 'unzip -l "' + file + '" 2> /dev/null';
exec(entryCommand,
function (error, stdout, stderr) {
if (error === null) {
console.error('Entries: ' + stdout);
callback(null, stdout);
} else {
console.error('exec error: ' + error);
callback(error, null);
}
});
// Do NodeJS version if the native version failed
}
};