Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knox

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knox - npm Package Compare versions

Comparing version 0.4.7 to 0.5.0

105

lib/client.js

@@ -67,2 +67,21 @@ /*!

/**
* Get headers needed for Client#copy and Client#copyTo.
*
* @param {String} sourceFilename
* @param {Object} headers
* @api private
*/
function getCopyHeaders(sourceBucket, sourceFilename, headers) {
sourceFilename = ensureLeadingSlash(sourceFilename);
headers = utils.merge({
Expect: '100-continue'
}, headers || {});
headers['x-amz-copy-source'] = '/' + sourceBucket + sourceFilename;
headers['Content-Length'] = 0; // to avoid Node's automatic chunking if omitted
return headers;
}
/**
* Initialize a `Client` with the given `options`.

@@ -90,2 +109,4 @@ *

}
// Save original options, we will need them for Client#copyTo
this.options = utils.merge({}, options);

@@ -332,10 +353,3 @@ var domain = 's3.amazonaws.com';

Client.prototype.copy = function(sourceFilename, destFilename, headers){
sourceFilename = ensureLeadingSlash(sourceFilename);
headers = utils.merge({
Expect: '100-continue'
}, headers || {});
headers['x-amz-copy-source'] = '/' + this.bucket + sourceFilename;
headers['Content-Length'] = 0; // to avoid Node's automatic chunking if omitted
return this.put(destFilename, headers);
return this.put(destFilename, getCopyHeaders(this.bucket, sourceFilename, headers));
};

@@ -367,2 +381,44 @@

/**
* Copy files from `sourceFilename` to `destFilename` of the bucket `destBucket`
* with optional `headers`.
*
* @param {String} sourceFilename
* @param {String} destFilename
* @param {Object} headers
* @return {ClientRequest}
* @api public
*/
Client.prototype.copyTo = function(sourceFilename, destBucket, destFilename, headers){
var options = utils.merge({}, this.options);
options.bucket = destBucket;
var client = exports.createClient(options);
return client.put(destFilename, getCopyHeaders(this.bucket, sourceFilename, headers));
};
/**
* Copy file from `sourceFilename` to `destFilename` of the bucket `destBucket
* with optional `headers` and callback `fn` with a possible exception and the response.
*
* @param {String} sourceFilename
* @param {String} destBucket
* @param {String} destFilename
* @param {Object|Function} headers
* @param {Function} fn
* @api public
*/
Client.prototype.copyFileTo = function(sourceFilename, destBucket, destFilename, headers, fn){
if ('function' == typeof headers) {
fn = headers;
headers = {};
}
var req = this.copyTo(sourceFilename, destBucket, destFilename, headers);
registerReqListeners(req, fn);
req.end();
return req;
};
/**
* GET `filename` with optional `headers`.

@@ -470,6 +526,7 @@ *

function xmlEscape(string) {
return string.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
return string
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}

@@ -479,5 +536,5 @@

var tags = keys.map(function(key){
return '<Object><Key>' +
xmlEscape(removeLeadingSlash(key)) +
'</Key></Object>';
return '<Object><Key>' +
xmlEscape(removeLeadingSlash(key)) +
'</Key></Object>';
});

@@ -500,3 +557,3 @@ return '<Delete>' + tags.join('') + '</Delete>';

throw new Error('Can only delete up to ' + BUCKET_OPS_MAX + ' files ' +
'at a time. You\'ll need to batch them.');
'at a time. You\'ll need to batch them.');
}

@@ -515,9 +572,9 @@

return this.request('POST', '/?delete', headers)
.on('response', function(res){
fn(null, res);
})
.on('error', function(err){
fn(err);
})
.end(xml);
.on('response', function(res){
fn(null, res);
})
.on('error', function(err){
fn(err);
})
.end(xml);
};

@@ -580,3 +637,3 @@

if (Array.isArray(data[key])) {
data[key].forEach(normalizeResponse);
data[key].forEach(normalizeResponse);
}

@@ -583,0 +640,0 @@ }

@@ -5,3 +5,3 @@ {

"keywords": ["aws", "amazon", "s3"],
"version": "0.4.7",
"version": "0.5.0",
"author": "TJ Holowaychuk <tj@learnboost.com>",

@@ -8,0 +8,0 @@ "contributors": [

@@ -152,3 +152,3 @@ # knox

Knox supports a few advanced operations. Like copying files:
Knox supports a few advanced operations. Like [copying files][copy]:

@@ -164,15 +164,31 @@ ```js

client.copyFile('/test/Readme.md', '/test/Readme.markdown', function(err, res){
// Logic
// ...
});
```
and deleting multiple files at once:
even between buckets:
```js
client.copyTo('/test/Readme.md', 'mirror-bucket', 'test/Readme.md').on('response', function(res){
// ...
}).end();
// or
client.copyFileTo('/test/Readme.md', 'mirror-bucket', 'test/Readme.md', function (err, res){
// ...
});
```
or [deleting multiple files at once][multi-delete]:
```js
client.deleteMultiple(['/test/Readme.md', '/test/Readme.markdown'], function(err, res){
// Logic
// ...
});
```
and [listing all the files in your bucket][list]:
or [listing all the files in your bucket][list]:

@@ -214,2 +230,4 @@ ```js

[copy]: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
[multi-delete]: http://docs.aws.amazon.com/AmazonS3/latest/API/multiobjectdeleteapi.html
[list]: http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGET.html

@@ -216,0 +234,0 @@ [acl]: http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGETacl.html

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc