forked from orangewise/s3-zip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3-zip.js
More file actions
41 lines (34 loc) · 970 Bytes
/
s3-zip.js
File metadata and controls
41 lines (34 loc) · 970 Bytes
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
var s3Files = require('s3-files');
var archiver = require('archiver');
module.exports = s3Zip = {};
s3Zip.archive = function (opts, folder, files) {
var self = this;
var keyStream = s3Files
.connect({
region: opts.region,
bucket: opts.bucket
})
.createKeyStream(folder, files);
var fileStream = s3Files.createFileStream(keyStream);
var archive = self.archiveStream(fileStream);
return archive;
};
s3Zip.archiveStream = function (stream) {
var archive = archiver('zip');
archive.on('error', function (err) {
console.log('archive error', err);
throw err;
});
stream
.on('data', function (file) {
// console.log(file.data.toString());
console.log('append to zip', file.path);
// archive.append(file, { name: 'x.png' });
archive.append(file.data, { name: file.path });
})
.on('end', function () {
console.log('end -> finalize');
archive.finalize();
});
return archive;
};