Skip to content

Commit

Permalink
Merge pull request #2 from jpalach/master
Browse files Browse the repository at this point in the history
possibility to pass s3 instance to constructor
  • Loading branch information
tzmanics committed Apr 15, 2016
2 parents fe8b521 + 21a2379 commit 88b6466
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ Example Usage

s3Sizer.getFolderSize('bucket.name', 'foldername', function(err, size) {
console.log(size)
});
});
If you already have s3 instance, you can pass it in parameter:

var s3 = new AWS.S3();
s3Sizer = new S3Sizer({"s3": s3});
28 changes: 16 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ var AWS = require('aws-sdk');
* accessKeyId is included then secretAccessKey must also be included.
* @config {string} [params.region] The AWS region to make calls against.
*/
var S3Sizer = function(params) {
if(params.hasOwnProperty('configFile')) {
AWS.config.loadFromPath(params.configFile);
}
var S3Sizer = function(params) {
if(params.hasOwnProperty('s3')) {
this.s3 = params.s3;
} else{
if(params.hasOwnProperty('configFile')) {
AWS.config.loadFromPath(params.configFile);
}

if(params.hasOwnProperty('accessKeyId') && params.hasOwnProperty('secretAccessKey')) {
AWS.config.update({accessKeyId : params.accessKeyId, secretAccessKey : params.secretAccessKey});
}
if(params.hasOwnProperty('accessKeyId') && params.hasOwnProperty('secretAccessKey')) {
AWS.config.update({accessKeyId : params.accessKeyId, secretAccessKey : params.secretAccessKey});
}

if(params.hasOwnProperty('region')) {
AWS.config.update({region : params.region});
}
if(params.hasOwnProperty('region')) {
AWS.config.update({region : params.region});
}

this.s3 = new AWS.S3();
};
this.s3 = new AWS.S3();
}
};

/**
* Gets the combined file size of all the objects in a S3 folder.
Expand Down

0 comments on commit 88b6466

Please sign in to comment.