Browse files

# metadata for blobs

  • Loading branch information...
1 parent d9b0183 commit 29077c6b711304de2a78c55b3dbcd7b275056f2c Juan Pablo Garcia Dalolla committed Aug 7, 2011
View
23 examples/blobs.js
@@ -4,42 +4,47 @@ waz.establishConnection( { accountName: 'your_account_name', accountKey: 'your_a
waz.blobs.container.create('test1', function(err, result){
console.log('\n_________| creating a container |_________\n');
- console.log(result || err);
+ console.log(err || result);
waz.blobs.container.create('test2', function(err, result){
console.log('\n_________| creating a container |_________\n');
- console.log(result || err);
+ console.log(err || result);
waz.blobs.container.list(function(err, result){
console.log('\n_________| listing existing containers |_________\n');
console.log(result || err.message);
result[0].putProperties({'x-ms-Custom' : 'MyValue'}, function(err, result){
- console.log(result);
+ console.log(err || result);
});
waz.blobs.container.find('test1', function(err, result){
console.log('\n_________| finding a container |_________\n');
- console.log(result || err);
+ console.log(err || result);
result.blobs(function(err, blobs){
- console.log(blobs)
+ console.log(err || blobs)
});
result.store('Folder/hello world.xml', '<xml/>', 'text/xml', {'x-ms-test': 'myvalue'}, function(err, result){
- console.log(result);
+ console.log(err || result);
});
result.getBlob('Folder/hello world.xml', function(err, blob){
- console.log(result);
+ console.log(err || result);
+
blob.getContents(function(err,data){
- console.log(data);
+ console.log(err || data);
+ });
+
+ blob.metadata(function(err, metadata){
+ console.log(err || metadata);
});
});
result.setAcl('container', function(err, result){
result.getAcl(function(err, result){
- console.log(result);
+ console.log(err || result);
});
});
View
6 lib/waz-blobs/blob.js
@@ -11,6 +11,12 @@ var Blob = module.exports = exports = function Blob(options) {
serviceInstance = options.serviceInstance;
}
+Blob.prototype.metadata = function(callback) {
+ serviceInstance.getBlobProperties(this.path, function(err, data) {
+ callback(err, data);
+ });
+};
+
Blob.prototype.getContents = function(callback){
serviceInstance.getBlob(this.path, function(err, data) {
callback(err, data);
View
2 lib/waz-blobs/container.js
@@ -1,5 +1,5 @@
var utils = require('../waz-storage/utils')
- , Blob = require('./blob');
+ , Blob = require('./blob');
var serviceInstance;
View
2 lib/waz-blobs/service.js
@@ -131,7 +131,7 @@ Service.prototype.setContainerAcl = function(name, level, callback){
Service.prototype.getBlobProperties = function(name, callback){
this.coreService.execute('head', name, null, {'x-ms-version': '2009-09-19'}, null, function(err, response) {
var error = null, data = null
-
+console.log(name)
if (err != null && err.statusCode == 400)
error = { message: 'blob `' + name + '` not found' };
else
View
43 lib/waz-storage/core-service.js
@@ -1,9 +1,9 @@
var crypto = require('crypto')
- ,querystring = require('querystring')
- ,http = require('http')
- ,https = require('https')
- ,url = require('url')
- ,utils = require('./utils');
+ , querystring = require('querystring')
+ , http = require('http')
+ , https = require('https')
+ , url = require('url')
+ , utils = require('./utils');
exports.CoreService = new CoreService({});
@@ -66,9 +66,9 @@ CoreService.prototype.canonicalizeMessage20090919 = function(url){
if (queryMatches && queryMatches.length > 0) {
queryComponent = "\n" + queryMatches[1].split('&')
- .map(function(p) { return unescape(p.split('=').join(':')); } )
- .sort(function(a,b){ return a.toLowerCase()>b.toLowerCase(); })
- .join('\n');
+ .map(function(p) { return unescape(p.split('=').join(':')); } )
+ .sort(function(a,b){ return a.toLowerCase()>b.toLowerCase(); })
+ .join('\n');
}
return "/" + this.accountName + "/" + uriComponent + queryComponent;
@@ -79,9 +79,9 @@ CoreService.prototype.generateSignature = function(options){
return this.generateSignature20090919(options);
var signature = options.method.toUpperCase() + "\x0A" +
- (options.headers["Content-MD5"] ? options.headers["Content-MD5"] : "") + "\x0A" +
- (options.headers["Content-Type"] ? options.headers["Content-Type"] : "") + "\x0A" +
- (options.headers["Date"] ? options.headers["Date"] : "") + "\x0A";
+ (options.headers["Content-MD5"] ? options.headers["Content-MD5"] : "") + "\x0A" +
+ (options.headers["Content-Type"] ? options.headers["Content-Type"] : "") + "\x0A" +
+ (options.headers["Date"] ? options.headers["Date"] : "") + "\x0A";
if (this.typeOfService != 'table')
signature += this.canonicalizeHeaders(options.headers) + "\x0A";
@@ -93,17 +93,17 @@ CoreService.prototype.generateSignature = function(options){
CoreService.prototype.generateSignature20090919 = function(options){
var signature = options.method.toUpperCase() + "\x0A" +
- (options.headers["Content-Encoding"] ? options.headers["Content-Encoding"] : "") + "\x0A" +
+ (options.headers["Content-Encoding"] ? options.headers["Content-Encoding"] : "") + "\x0A" +
(options.headers["Content-Language"] ? options.headers["Content-Language"] : "") + "\x0A" +
(options.headers["Content-Length"] ? options.headers["Content-Length"] : "0") + "\x0A" +
- (options.headers["Content-MD5"] ? options.headers["Content-MD5"] : "") + "\x0A" +
- (options.headers["Content-Type"] ? options.headers["Content-Type"] : "") + "\x0A" +
- (options.headers["Date"] ? options.headers["Date"] : "") + "\x0A" +
- (options.headers["If-Modified-Since"] ? options.headers["If-Modified-Since"] : "") + "\x0A" +
- (options.headers["If-Match"] ? options.headers["If-Match"] : "") + "\x0A" +
- (options.headers["If-None-Match"] ? options.headers["If-None-Match"] : "") + "\x0A" +
- (options.headers["If-Unmodified-Since"] ? options.headers["If-Unmodified-Since"] : "") + "\x0A" +
- (options.headers["Range"] ? options.headers["Range"] : "") + "\x0A" +
+ (options.headers["Content-MD5"] ? options.headers["Content-MD5"] : "") + "\x0A" +
+ (options.headers["Content-Type"] ? options.headers["Content-Type"] : "") + "\x0A" +
+ (options.headers["Date"] ? options.headers["Date"] : "") + "\x0A" +
+ (options.headers["If-Modified-Since"] ? options.headers["If-Modified-Since"] : "") + "\x0A" +
+ (options.headers["If-Match"] ? options.headers["If-Match"] : "") + "\x0A" +
+ (options.headers["If-None-Match"] ? options.headers["If-None-Match"] : "") + "\x0A" +
+ (options.headers["If-Unmodified-Since"] ? options.headers["If-Unmodified-Since"] : "") + "\x0A" +
+ (options.headers["Range"] ? options.headers["Range"] : "") + "\x0A" +
this.canonicalizeHeaders(options.headers) + "\x0A" +
this.canonicalizeMessage20090919(options.url);
@@ -141,8 +141,9 @@ CoreService.prototype.execute = function(verb, path, query, headers, payload, ca
response.addListener('data', function (chunk) {
body.push(chunk);
});
-
+ console.log(response.statusCode)
response.addListener('end', function () {
+
if (response.statusCode >= 400)
error = { statusCode: response.statusCode };
else
View
29 test/waz-blobs/blob.test.js
@@ -1,8 +1,8 @@
var waz = require('waz-storage')
- , assert = require('assert')
- , sinon = require('sinon')
- , Blob = require('../../lib/waz-blobs/blob')
- , Service = require('../../lib/waz-blobs/service');
+ , assert = require('assert')
+ , sinon = require('sinon')
+ , Blob = require('../../lib/waz-blobs/blob')
+ , Service = require('../../lib/waz-blobs/service');
module.exports = {
@@ -26,7 +26,7 @@ module.exports = {
var blobService = new Service({});
var mock = sinon.mock(blobService);
- var blob = new Blob({name: 'blob_name', url: 'http://localhost/containerName/my%20Blob', contentType: 'text/xml', serviceInstance: blobService});
+ var blob = new Blob({name: 'blobName', url: 'http://localhost/containerName/my%20Blob', contentType: 'text/xml', serviceInstance: blobService});
mock.expects("getBlob").withArgs("containerName/my%20Blob")
.yields(null, '<xml>value</xml>')
@@ -38,5 +38,24 @@ module.exports = {
});
mock.verify();
+ },
+
+ 'should be able to return metadata from a given blob': function(){
+ waz.establishConnection({ accountName : 'name', accountKey : 'key' });
+ var blobService = new Service({});
+ var mock = sinon.mock(blobService);
+
+ var mockData = { 'x-ms-Name' : "containerName", 'x-ms-CustomProperty' : "customPropertyValue" };
+ mock.expects("getBlobProperties").withArgs("containerName/blobName").yields(null, mockData).once();
+
+ var blob = new Blob({name: 'blobName', url: 'http://localhost/containerName/blobName', contentType: 'text/xml', serviceInstance: blobService});
+
+ blob.metadata(function(err, metadata){
+ assert.equal(Object.keys(metadata).length, 2)
+ assert.equal(metadata['x-ms-Name'], "containerName");
+ assert.equal(metadata['x-ms-CustomProperty'], "customPropertyValue");
+ });
+
+ mock.verify();
},
}
View
11 test/waz-blobs/container.test.js
@@ -1,6 +1,6 @@
var waz = require('waz-storage')
- , assert = require('assert')
- , sinon = require('sinon');
+ , assert = require('assert')
+ , sinon = require('sinon');
module.exports = {
@@ -62,14 +62,15 @@ module.exports = {
waz.establishConnection({ accountName : 'name', accountKey : 'key' });
var mock = sinon.mock(waz.blobs.container.serviceInstance);
- var mockData = { 'x-meta-Name' : "containerName", 'x-meta-CustomProperty' : "customPropertyValue" };
+ var mockData = { 'x-ms-Name' : "containerName", 'x-ms-CustomProperty' : "customPropertyValue" };
mock.expects("getContainerProperties").withArgs("containerName").yields(null, mockData).twice();
waz.blobs.container.find('containerName', function (err, container) {
container.metadata(function(err, metadata) {
- assert.equal(metadata['x-meta-Name'], "containerName");
- assert.equal(metadata['x-meta-CustomProperty'], "customPropertyValue");
+ assert.equal(metadata['x-ms-Name'], "containerName");
+ assert.equal(metadata['x-ms-CustomProperty'], "customPropertyValue");
+ assert.equal(Object.keys(metadata).length, 2)
assert.isNull(err);
});
});
View
8 test/waz-blobs/service.test.js
@@ -1,7 +1,7 @@
var waz = require('waz-storage')
- , assert = require('assert')
- , sinon = require('sinon')
- , Service = require('../../lib/waz-blobs/service');
+ , assert = require('assert')
+ , sinon = require('sinon')
+ , Service = require('../../lib/waz-blobs/service');
module.exports = {
@@ -85,7 +85,7 @@ module.exports = {
mock.verify();
},
-
+
'should get blob properties': function(){
var blobService = new Service({});
var mock = sinon.mock(blobService.coreService);
View
4 test/waz-storage/core-service.test.js
@@ -1,6 +1,6 @@
var CoreService = require('waz-storage/core-service')
- , assert = require('assert')
- , sinon = require('sinon');
+ , assert = require('assert')
+ , sinon = require('sinon');
module.exports = {

0 comments on commit 29077c6

Please sign in to comment.