Skip to content

Commit

Permalink
type: feat
Browse files Browse the repository at this point in the history
Added new parameter "useCredentials" on constructor to choce if want use key/secret or credentials file on loca folder. Issue DanielHindi#21

Added new parameter "folderPath" on zipToS3File to choce if want bucket folder structure inside zip file or only files. Issue DanielHindi#20

Resolves: DanielHindi#21, DanielHindi#20
  • Loading branch information
Felipe Romani committed Feb 6, 2018
1 parent dd41278 commit 3422c09
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ var s3 = require('s3');

function S3Zipper(awsConfig) {
assert.ok(awsConfig, 'AWS S3 options must be defined.');
assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.');
assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret');
if (!awsConfig.useCredentials) {
assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.');
assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret');
}
assert.notEqual(awsConfig.region, undefined, 'Requires AWS S3 region.');
assert.notEqual(awsConfig.bucket, undefined, 'Requires AWS S3 bucket.');
this.init(awsConfig);
Expand Down Expand Up @@ -38,12 +40,10 @@ S3Zipper.prototype = {
, filterOutFiles: function (fileObj) {
return fileObj;
}
, calculateFileName: function (f) {
, calculateFileName: function (f, params) {
var name = f.Key.split("/");
name.shift();
name = name.join("/");
return name;

return !params.folderPath ? name[name.length-1] : name.join("/");
}

/*
Expand Down Expand Up @@ -181,7 +181,7 @@ S3Zipper.prototype = {
callback(err);
else {

var name = t.calculateFileName(f);
var name = t.calculateFileName(f, params);

if (name === ""){
callback(null, f);
Expand Down Expand Up @@ -265,6 +265,7 @@ S3Zipper.prototype = {
,startKey:arguments[1]
,s3ZipFileName:arguments[2]
,recursive: false
,folderPath: typeof params.folderPath == 'boolean' ? params.folderPath : true
};
callback= arguments[3];
}
Expand Down Expand Up @@ -390,6 +391,7 @@ S3Zipper.prototype = {
, startKey:arguments[1]
, zipFileName:arguments[2]
, recursive: false
, folderPath: params.folderPath
};
callback= arguments[3];
}
Expand Down

0 comments on commit 3422c09

Please sign in to comment.