Skip to content

Commit

Permalink
dont upload empty zip
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHindi committed Mar 7, 2016
1 parent 06c794b commit a62e8e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
64 changes: 37 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,44 @@ S3Zipper.prototype = {
this.zipToFile(s3FolderName,startKey,tempFile ,function(err,r){
console.log('uploading ',s3ZipFileName,'...');

var readStream = fs.createReadStream(tempFile);//tempFile

t.s3bucket.upload({
Bucket: t.awsConfig.bucket
,Key :s3ZipFileName
,ContentType:"application/zip"
,Body:readStream
})
.on('httpUploadProgress', function(e) {
console.log('upload progress', Math.round(e.loaded/ e.total * 100,0) ,'%' );

})
.send(function(err, result) {
readStream.close();
if(err)
callback(err);
else {
console.log('zip upload completed.');

callback(null, {
zipFileETag: result.ETag,
zipFileLocation: result.Location,
zippedFiles: r.manifest
});
fs.unlink(tempFile);
}
if(r && r.manifest && r.manifest.length) {
var readStream = fs.createReadStream(tempFile);//tempFile

t.s3bucket.upload({
Bucket: t.awsConfig.bucket
, Key: s3ZipFileName
, ContentType: "application/zip"
, Body: readStream
})
.on('httpUploadProgress', function (e) {
console.log('upload progress', Math.round(e.loaded / e.total * 100, 0), '%');

})
.send(function (err, result) {
readStream.close();
if (err)
callback(err);
else {
console.log('zip upload completed.');

callback(null, {
zipFileETag: result.ETag,
zipFileLocation: result.Location,
zippedFiles: r.manifest
});
fs.unlink(tempFile);
}
});
}
else {
console.log('no files zipped. nothing to upload');
fs.unlink(tempFile);
callback(null, {
zipFileETag: null,
zipFileLocation: null,
zippedFiles: []
});

}
});


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-s3-zipper",
"version": "0.0.7",
"version": "0.0.8",
"description": "Zips an Amazon S3 directory as a stream or file. Allows filtering files",
"main": "index.js",
"dependencies": {
Expand Down

0 comments on commit a62e8e3

Please sign in to comment.