From edcd962b7ad8b40637ba68df6f0a5952fc892012 Mon Sep 17 00:00:00 2001 From: Mark Bogdanoff Date: Fri, 20 Apr 2012 10:06:28 -0700 Subject: [PATCH 1/2] adding getFileInfo to perform a HEAD request on the object and return a storage object representing the remote object --- lib/cloudfiles/core.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 From b396491e0848516796b1f4924320cedfa8ebeaf3 Mon Sep 17 00:00:00 2001 From: Mark Bogdanoff Date: Fri, 20 Apr 2012 11:47:32 -0700 Subject: [PATCH 2/2] adding getFileInfo tests --- test/storage-object-test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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": {