Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cleanup metadata implementation #49

Open
wants to merge 1 commit into from

3 participants

@bxjx

addMetadata and getMetadata now work as intended. Relevant test have been uncommented. Thanks for the great library!

@bromanko

+1 for merging this. The current getMetaData call does not function at all.

@indexzero
Owner

Sorry for the delay here! We've been waiting on all the issues / pull-requests for node-cloudfiles and node-cloudservers until we released pkgcloud: a new cross-provider unified IaaS library for node.js:

https://github.com/nodejitsu/pkgcloud
http://blog.nodejitsu.com/introducing-pkgcloud

We added a deprecation notice for this library, but would you consider reimplementing your pull-request for the Rackspace provider in pkgcloud? It would make you a HERO in my book :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 14, 2012
  1. @bxjx

    Cleanup metadata implementation

    bxjx authored
This page is out of date. Refresh to see the latest.
View
23 lib/cloudfiles/storage-object.js
@@ -20,21 +20,19 @@ var StorageObject = exports.StorageObject = function (client, details) {
};
StorageObject.prototype = {
- // Remark: Not fully implemented
+
addMetadata: function (metadata, callback) {
- var newMetadata = clone(this.metadata);
- Object.keys(metadata).forEach(function (key) {
- newMetadata[key] = metadata[key];
- });
+ var self = this;
var options = {
+ client: this.client,
uri: this.fullPath,
method: 'POST',
- headers: this._createHeaders(newMetadata)
+ headers: this._createHeaders(metadata)
};
common.rackspace(options, callback, function (body, res) {
- this.metadata = newMetadata;
+ self.metadata = metadata;
callback(null, true);
});
},
@@ -59,13 +57,18 @@ StorageObject.prototype = {
this.client.destroyFile(this.containerName, this.name, callback);
},
- // Remark: Not fully implemented
getMetadata: function (callback) {
- common.rackspace('HEAD', this.fullPath, function (body, res) {
+ var options = {
+ client: this.client,
+ uri: this.fullPath,
+ method: 'HEAD',
+ };
+
+ common.rackspace(options, callback, function (body, res) {
var metadata = {};
Object.keys(res.headers).forEach(function (header) {
var match;
- if (match = header.match(/x-object-meta-(\w+)/i)) {
+ if (match = header.match(/x-object-meta-(.*)/i)) {
metadata[match[1]] = res.headers[header];
}
});
View
14 test/storage-object-metadata-test.js
@@ -17,7 +17,7 @@ var testData = {},
client = helpers.createClient(),
sampleData = fs.readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')).toString();
-vows.describe('node-cloudfiles/storage-object').addBatch({
+vows.describe('node-cloudfiles/storage-object').addBatch(helpers.requireAuth(client)).addBatch({
"The node-cloudfiles client": {
"an instance of a Container object": {
"the addFile() method": {
@@ -49,14 +49,16 @@ vows.describe('node-cloudfiles/storage-object').addBatch({
}
}
}
-})/*.addBatch({
+}).addBatch({
"The node-cloudfiles client": {
"the addMetadata() method": {
topic: function () {
- testData.file.addMetadata({ "ninja": "true" }, this.callback);
+ testData.metadata = { "ninja-metadata": "true" };
+ testData.file.addMetadata(testData.metadata, this.callback);
},
"should response with true": function (err, added) {
assert.isTrue(added);
+ assert.deepEqual(testData.file.metadata, testData.metadata);
}
}
}
@@ -66,12 +68,12 @@ vows.describe('node-cloudfiles/storage-object').addBatch({
topic: function () {
testData.file.getMetadata(this.callback);
},
- "should response with true": function (err, added) {
- assert.isTrue(added);
+ "should return the metadata as an object": function (err, metadata) {
+ assert.deepEqual(metadata, testData.metadata);
}
}
}
-})*/.addBatch({
+}).addBatch({
"The node-cloudfiles client": {
"the destroyFile() method": {
"for a file that exists": {
Something went wrong with that request. Please try again.