diff --git a/lib/cloudfiles/core.js b/lib/cloudfiles/core.js index 524ad3a..2fef356 100644 --- a/lib/cloudfiles/core.js +++ b/lib/cloudfiles/core.js @@ -343,6 +343,35 @@ Cloudfiles.prototype.getFile = function (container, filename, callback) { }); }; +Cloudfiles.prototype.getFileInfo = function (container, filename, callback) { + var self = this, + containerPath = path.join(this.config.cache.path, container), + options; + + common.statOrMkdirp(containerPath); + + var options; + + options = { + method: 'HEAD', + client: self, + uri: self.storageUrl(container, filename) + }; + + common.rackspace(options, callback, function (body, res) { + var file = { + container: container, + name: filename, + bytes: res.headers['content-length'], + etag: res.headers['etag'], + last_modified: res.headers['last-modified'], + content_type: res.headers['content-type'] + }; + + callback(null, new (cloudfiles.StorageObject)(self, file)); + }); +}; + // // options // remote diff --git a/test/storage-object-test.js b/test/storage-object-test.js index aee0bdf..fc2e397 100644 --- a/test/storage-object-test.js +++ b/test/storage-object-test.js @@ -114,6 +114,29 @@ vows.describe('node-cloudfiles/storage-object').addBatch(helpers.requireAuth(cli } } } +}).addBatch({ + "The node-cloudfiles client": { + "the getFileInfo() method": { + "for a file that exists": { + topic: function () { + client.getFileInfo('test_container', 'file2.txt', this.callback); + }, + "should return a valid StorageObject": function (err, file) { + helpers.assertFile(file); + assert.isNull(file.local); + testData.file = file; + } + } + , "for a file that does not exist": { + topic: function () { + client.getFileInfo('test_container', 'file0.txt', this.callback); + }, + "should return an error": function (err, file) { + assert.ok(err instanceof Error); + } + } + } + } }).addBatch({ "The node-cloudfiles client": { "an instance of StorageObject": {