Permalink
Browse files

# just published v0.1.0 @ http://search.npmjs.org/#/waz-storage-js

  • Loading branch information...
Juan Pablo Garcia Dalolla
Juan Pablo Garcia Dalolla committed Aug 1, 2011
1 parent 2cec4d6 commit 85048ed8e7d1c2378c16ee1040563e10a3eb995c
View
@@ -1,3 +1,3 @@
-0.0.1 / 2011-07-31
+0.1.0 / 2011-07-31
==================
* Initial Release: Basic support for Blobs
View
@@ -52,7 +52,12 @@ To install via npm
});
// Getting blob's information
- result.getBlob('myfolder/my file.txt', function(err, result){
+ result.getBlob('myfolder/my file.txt', function(err, blob){
+
+ // Getting blob's contents
+ blob.getContents(function(err,data){
+ console.log(data);
+ });
});
// Uploading a new Blob
@@ -73,10 +78,14 @@ To install via npm
# Remaining Stuff
+* Documentation
+* SharedAccessSignature
## Blobs
+* Copy / Delete / Snapshot
+* Metadata (get/put)
+* Update contents
* Blocks
-* Snapshots
## Queues
* Everything
View
@@ -1,4 +1,4 @@
-var waz = require('../');
+var waz = require('waz-storage-js');
waz.establishConnection( { accountName: 'your_account_name', accountKey: 'your_account_key', useSsl: false } );
@@ -30,8 +30,11 @@ waz.blobs.container.create('test1', function(err, result){
console.log(result);
});
- result.getBlob('Folder/hello world.xml', function(err, result){
+ result.getBlob('Folder/hello world.xml', function(err, blob){
console.log(result);
+ blob.getContents(function(err,data){
+ console.log(data);
+ });
});
result.setAcl('container', function(err, result){
View
@@ -11,3 +11,8 @@ var Blob = module.exports = exports = function Blob(options) {
serviceInstance = options.serviceInstance;
}
+Blob.prototype.getContents = function(callback){
+ serviceInstance.getBlob(this.path, function(err, data) {
+ callback(err, data);
+ });
+}
@@ -39,7 +39,7 @@ Container.prototype.setAcl = function(level, callback) {
Container.prototype.blobs = function(callback) {
serviceInstance.listBlobs(this.name, function(err, data) {
- var blobs = data.map(function(b){ return new Blob(b) });
+ var blobs = data.map(function(b) { return new Blob(b.merge({serviceInstance : serviceInstance })) });
callback(err, blobs);
});
};
@@ -51,7 +51,7 @@ Container.prototype.getBlob = function(name, callback) {
serviceInstance.getBlobProperties(path, function(err, data) {
// TODO: error handling
var url = serviceInstance.generateRequestUri(path, {});
- var blob = new Blob( { name: name, contentType: data['content-type'], url: url});
+ var blob = new Blob( { name: name, contentType: data['content-type'], url: url}.merge({serviceInstance : serviceInstance}));
callback(err, blob);
});
};
@@ -63,7 +63,7 @@ Container.prototype.store = function(name, payload, contentType, metadata, callb
serviceInstance.putBlob(path, payload, contentType, metadata, function(err, data) {
// TODO: error handling
var url = serviceInstance.generateRequestUri(path, {});
- var blob = new Blob( { name: name, contentType: contentType, url: url});
+ var blob = new Blob( { name: name, contentType: contentType, url: url}.merge({serviceInstance : serviceInstance}));
callback(err, blob);
});
};
View
@@ -157,6 +157,19 @@ Service.prototype.putBlob = function(path, payload, contentType, metadata, callb
});
}
+Service.prototype.getBlob = function(path, callback){
+ this.coreService.execute('get', path, null, {'x-ms-version': '2009-09-19'}, null, function(err, response) {
+ var error = null, data = null
+
+ if (err != null && err.statusCode == 404)
+ error = { message: 'blob `' + name + '` not found' };
+ else
+ data = response.body;
+
+ callback(error, data);
+ });
+}
+
Service.prototype.generateRequestUri = function(path, options){
return this.coreService.generateRequestUri(path, options);
}
View
@@ -10,4 +10,4 @@ exports = module.exports = require('./base');
* @type String
*/
-exports.version = '0.0.1';
+exports.version = '0.1.0';
View
@@ -1,6 +1,6 @@
{
"name": "waz-storage-js",
- "version": "0.0.1",
+ "version": "0.1.0",
"description": "Windows Azure Storage library for Node JS",
"keywords": ["azure", "waz", "windows", "blobs", "queues", "tables"],
"homepage": "https://github.com/jpgarcia/waz-storage-js",
@@ -1,22 +1,42 @@
var waz = require('waz-storage')
, assert = require('assert')
, sinon = require('sinon')
- , Blob = require('../../lib/waz-blobs/blob');
+ , Blob = require('../../lib/waz-blobs/blob')
+ , Service = require('../../lib/waz-blobs/service');
module.exports = {
'should return blob path from url': function(){
- var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob', contentType: 'application/xml'})
+ var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob', contentType: 'text/xml'})
assert.equal(blob.path, "container/blob");
},
'blob path should include snapshot parameter': function(){
- var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob?snapshot=foo', contentType: 'application/xml'})
+ var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob?snapshot=foo', contentType: 'text/xml'});
assert.equal(blob.path, "container/blob?snapshot=foo");
},
'blob path should not include additional parameters': function(){
- var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob?snapshot=foo&additional=true', contentType: 'application/xml'})
+ var blob = new Blob({name: 'blob_name', url: 'http://localhost/container/blob?snapshot=foo&additional=true', contentType: 'text/xml'})
assert.equal(blob.path, "container/blob?snapshot=foo");
},
+
+ 'should get blob contents': function(){
+ waz.establishConnection({ accountName : 'name', accountKey : 'key' });
+ 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});
+
+ mock.expects("getBlob").withArgs("containerName/my%20Blob")
+ .yields(null, '<xml>value</xml>')
+ .once();
+
+ blob.getContents(function(err, data){
+ assert.isNull(err);
+ assert.equal(data, '<xml>value</xml>');
+ });
+
+ mock.verify();
+ },
}
Oops, something went wrong.

0 comments on commit 85048ed

Please sign in to comment.