-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.js
30 lines (23 loc) · 771 Bytes
/
zip.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
var spawn = require('child_process').spawn;
var sys = require("util");
var EventEmitter = require("events").EventEmitter;
var zip = function(dir, bufferList, timestamp) {
EventEmitter.call(this);
var _self = this;
var zipProcess = spawn('zip', ['-rj', '-', dir]);
var file_contents = '';
zipProcess.stdout.setEncoding('binary')
zipProcess.stdout.on('data', function (data) {
file_contents += data;
});
zipProcess.stderr.on('data', function (data) {
//_self.emit("error", data);
});
// End the response on zip exit
zipProcess.on('exit', function (code) {
bufferList.push(new Buffer(file_contents, "binary"));
_self.emit("complete");
});
}
sys.inherits(zip, EventEmitter);
module.exports = zip;