Automattic / knox

S3 Lib
MIT License
1.74k stars 285 forks source link

Allow head requests for S3 buckets #309

Open radiovisual opened 8 years ago

radiovisual commented 8 years ago

I am simply trying to do a head request to check the existence of an S3 Bucket.

If I were using the aws-sdk, I would use the aws-sdk's headObject method and do this:

var AWS = require('aws-sdk');
var s3 = new AWS.S3();

s3.headObject({Bucket: 'someBucket'}, function(err, data) {
    if (err) {
        console.log(err, err.stack);
    } else {
        console.log('The bucket exists!');
    }
});

I see that knox has a client.head() method, which seems to need a path to a file, like this:

 client.head('path/to/file').on('response', function (res) {
    // ...     
 });

But is there a way to use knox to just grab the HEAD of a bucket?

Something like:

 client.head('bucketName').on('response', function (res) {
    // ...     
 });

Thanks!