Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getFileInfo method to client #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/cloudfiles/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/storage-object-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down