Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 85048ed8e7d1c2378c16ee1040563e10a3eb995c 1 parent 2cec4d6
Juan Pablo Garcia Dalolla authored
View
2  History.md
@@ -1,3 +1,3 @@
-0.0.1 / 2011-07-31
+0.1.0 / 2011-07-31
==================
* Initial Release: Basic support for Blobs
View
13 Readme.md
@@ -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
7 examples/blobs.js
@@ -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
5 lib/waz-blobs/blob.js
@@ -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);
+ });
+}
View
6 lib/waz-blobs/container.js
@@ -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
13 lib/waz-blobs/service.js
@@ -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
2  lib/waz-storage/index.js
@@ -10,4 +10,4 @@ exports = module.exports = require('./base');
* @type String
*/
-exports.version = '0.0.1';
+exports.version = '0.1.0';
View
2  package.json
@@ -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",
View
28 test/waz-blobs/blob.test.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();
+ },
}
View
66 test/waz-blobs/container.test.js
@@ -13,10 +13,11 @@ module.exports = {
mock.expects("createContainer").withArgs("myContainer").yields(null, mockData).once();
waz.blobs.container.create('myContainer', function(err, container){
- mock.verify();
assert.equal(container.name, "containerName");
assert.isNull(err);
});
+
+ mock.verify();
},
'should be able to delete a container': function(){
@@ -27,9 +28,10 @@ module.exports = {
mock.expects("deleteContainer").withArgs("existing").yields(null, null).once();
waz.blobs.container.delete('existing', function(err){
- mock.verify();
assert.isNull(err);
});
+
+ mock.verify();
},
'should list containers': function(){
@@ -40,9 +42,7 @@ module.exports = {
mock.expects("listContainers").withArgs().yields(null, mockData).once();
- waz.blobs.container.list(function(err, containers){
- mock.verify();
-
+ waz.blobs.container.list(function(err, containers){
assert.equal(containers.length, 2);
assert.equal(containers[0].name, "container1");
assert.equal(containers[0].url, "url1");
@@ -54,6 +54,8 @@ module.exports = {
assert.isNull(err);
});
+
+ mock.verify();
},
'should be able to return metadata from a given container': function(){
@@ -66,12 +68,13 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.metadata(function(err, metadata) {
- mock.verify();
assert.equal(metadata['x-meta-Name'], "containerName");
assert.equal(metadata['x-meta-CustomProperty'], "customPropertyValue");
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should be able to add metadata to a container': function(){
@@ -87,11 +90,12 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.putProperties(metadata, function(err, metadata) {
- mock.verify();
assert.isNull(metadata);
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should be able to return a container by name': function(){
@@ -103,10 +107,11 @@ module.exports = {
mock.expects("getContainerProperties").withArgs("containerName").yields(null, mockData).once();
waz.blobs.container.find('containerName', function(err, container){
- mock.verify();
assert.equal(container.name, "containerName");
assert.isNull(err);
});
+
+ mock.verify();
},
'should get None when ACL is null': function(){
@@ -121,11 +126,12 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.getAcl(function(err, data){
- mock.verify();
assert.equal(data, "None");
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should be able to get the ACL': function(){
@@ -140,11 +146,12 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.getAcl(function(err, data){
- mock.verify();
assert.equal(data, "container");
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should set container ACL to blob': function(){
@@ -158,11 +165,12 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.setAcl('blob', function(err, data){
- mock.verify();
assert.equal(data, container);
assert.isNull(err);
});
});
+
+ mock.verify();
},
'should list blobs in a container': function(){
@@ -180,7 +188,6 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.blobs(function(err, data){
- mock.verify();
assert.equal(data.length, 2);
assert.equal(data[0].name, 'blob1');
assert.equal(data[0].url, 'http://localhost/container/blob1');
@@ -192,7 +199,9 @@ module.exports = {
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should return an empty array if container doesn\'t have blobs': function(){
@@ -209,11 +218,12 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.blobs(function(err, data){
- mock.verify();
assert.equal(data.length, 0);
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should return a blob instance by a given name': function(){
@@ -231,14 +241,15 @@ module.exports = {
mock.expects("generateRequestUri").withArgs("containerName/myBlob", {}).returns(mockUrl).once();
waz.blobs.container.find('containerName', function (err, container) {
- container.getBlob('myBlob', function(err, blob){
- mock.verify();
+ container.getBlob('myBlob', function(err, blob){
assert.equal(blob.name, 'myBlob');
assert.equal(blob.contentType, 'text/xml');
assert.equal(blob.url, 'http://mock-account.blob.core.windows.net/containerName/myBlob');
assert.isNull(err);
});
});
+
+ mock.verify();
},
'should return a blob instance by a given un-escaped name': function(){
@@ -257,13 +268,14 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.getBlob('my Blob', function(err, blob){
- mock.verify();
assert.equal(blob.name, 'my Blob');
assert.equal(blob.contentType, 'text/xml');
assert.equal(blob.url, 'http://mock-account.blob.core.windows.net/containerName/my%20Blob');
assert.isNull(err);
});
});
+
+ mock.verify();
},
'should store a blob': function(){
@@ -280,13 +292,14 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.store('my Blob', '<xml><sample>value</sample></xml>', 'text/xml', {'x-ms-test': 'value'}, function(err, blob){
- mock.verify();
assert.equal(blob.name, 'my Blob');
assert.equal(blob.contentType, 'text/xml');
assert.equal(blob.url, 'http://mock-account.blob.core.windows.net/containerName/my%20Blob');
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
'should store a blob with default content-type': function(){
@@ -303,12 +316,13 @@ module.exports = {
waz.blobs.container.find('containerName', function (err, container) {
container.store('my Blob', '<xml><sample>value</sample></xml>', null, {'x-ms-test': 'value'}, function(err, blob){
- mock.verify();
assert.equal(blob.name, 'my Blob');
assert.equal(blob.contentType, 'application/octet-stream');
assert.equal(blob.url, 'http://mock-account.blob.core.windows.net/containerName/my%20Blob');
assert.isNull(err);
});
- });
+ });
+
+ mock.verify();
},
}
View
27 test/waz-blobs/service.test.js
@@ -378,11 +378,29 @@ module.exports = {
.once();
var properties = blobService.putBlob('mock-container/blob', 'payload', 'text/xml', {'x-ms-CustomProp': 'value'}, function(err, properties){
- mock.verify();
assert.isNull(err);
});
+
+ mock.verify();
},
-
+
+ 'should get blob contents': function(){
+ var blobService = new Service({});
+ var mock = sinon.mock(blobService.coreService);
+ var mockData = {body: '<xml></xml>', headers: null};
+
+ mock.expects("execute").withArgs('get', 'mock-container/blob', null, {'x-ms-version': '2009-09-19'}, null)
+ .yields(null, mockData)
+ .once();
+
+ var properties = blobService.getBlob('mock-container/blob', function(err, data){
+ assert.isNull(err);
+ assert.equal(data, mockData.body);
+ });
+
+ mock.verify();
+ },
+
'should store a blob if metadata if not specified': function(){
var blobService = new Service({});
var mock = sinon.mock(blobService.coreService);
@@ -393,9 +411,10 @@ module.exports = {
.yields(null, mockData)
.once();
- var properties = blobService.putBlob('mock-container/blob', 'payload', 'text/xml', null, function(err, properties){
- mock.verify();
+ var properties = blobService.putBlob('mock-container/blob', 'payload', 'text/xml', null, function(err, data){
assert.isNull(err);
});
+
+ mock.verify();
},
}
Please sign in to comment.
Something went wrong with that request. Please try again.