Skip to content

Commit

Permalink
Add multi-objects delete
Browse files Browse the repository at this point in the history
  • Loading branch information
linyows committed Mar 7, 2012
1 parent eabef00 commit 0621184
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Readme.md
Expand Up @@ -105,6 +105,19 @@ Likewise we also have `client.deleteFile()` as a more concise (yet less flexible
// Logic
});

Delete multi-objects

var json2xml = require('json2xml');
var xml_data = '<?xml version="1.0" encoding="UTF-8"?>' + json2xml.toXml('Delete', { Object: [
{ Key: '0/0/0.png'},
{ Key: '0/0/1.png'},
{ Key: '0/0/2.png'}
]});
client.deleteAll(xml_data, function(err, res){
console.log(res.statusCode);
console.log(res.headers);
});

## Running Tests

To run the test suite you must first have an S3 account, and create
Expand Down
1 change: 1 addition & 0 deletions lib/knox/auth.js
Expand Up @@ -31,6 +31,7 @@ var keys = [
, 'versioning'
, 'versions'
, 'website'
, 'delete'
];

/**
Expand Down
24 changes: 24 additions & 0 deletions lib/knox/client.js
Expand Up @@ -297,6 +297,30 @@ Client.prototype.deleteFile = function(filename, headers, fn){
}).end();
};

/**
* DELETE `elements` with optional `headers`
* and callback `fn` with a possible exception and the response.
*
* @param {String} elements
* @param {Object|Function} headers
* @param {Function} fn
* @api public
*/

Client.prototype.deleteAll = function(elements, headers, fn){
if ('function' == typeof headers) {
fn = headers;
headers = {};
}
headers = utils.merge({
'Content-Length': elements.length
, 'Content-MD5': crypto.createHash('md5').update(elements).digest('base64')
}, headers);
return this.request('POST', '/?delete', headers).on('response', function(res){
fn(null, res);
}).end(elements);
};

/**
* Return a url to the given `filename`.
*
Expand Down

0 comments on commit 0621184

Please sign in to comment.