diff --git a/Readme.md b/Readme.md index e53e094..807691e 100644 --- a/Readme.md +++ b/Readme.md @@ -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 = '' + 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 diff --git a/lib/knox/auth.js b/lib/knox/auth.js index 4e87bff..604da08 100644 --- a/lib/knox/auth.js +++ b/lib/knox/auth.js @@ -31,6 +31,7 @@ var keys = [ , 'versioning' , 'versions' , 'website' + , 'delete' ]; /** diff --git a/lib/knox/client.js b/lib/knox/client.js index 9ee081d..534a816 100644 --- a/lib/knox/client.js +++ b/lib/knox/client.js @@ -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`. *