Permalink
Browse files

# adding support for block uploads

  • Loading branch information...
1 parent 2479342 commit ca735b17c87aaa29028f07a78875813774fadf10 Juan Pablo Garcia Dalolla committed Sep 7, 2011
Showing with 333 additions and 112 deletions.
  1. +5 −0 History.md
  2. +122 −76 Readme.md
  3. +46 −25 examples/blobs.js
  4. +49 −1 lib/waz-blobs/container.js
  5. +35 −1 lib/waz-blobs/service.js
  6. +1 −1 lib/waz-storage/index.js
  7. +3 −2 package.json
  8. +53 −6 test/waz-blobs/container.test.js
  9. +19 −0 test/waz-blobs/service.test.js
View
@@ -1,3 +1,8 @@
+0.1.2 / TBD
+==================
+* Added remaining Blob functionality:
+ - Support for Blocks
+
0.1.1 / 2011-08-22
==================
* Added remaining Blob functionality:
View
@@ -20,92 +20,136 @@ To install via npm
## Blobs
- // Creating a new container
- waz.blobs.container.create('myContainer', function(err, container){
- });
+ waz.blobs.container.create('container1', function(err, container1) {
+ console.log('\n_________| creating a container |_________\n');
+ console.log(err || container1);
- // Listing existing containers
- waz.blobs.container.list(function(err, containers){
- });
+ waz.blobs.container.create('container2', function(err, container2) {
+ console.log('\n_________| creating another container |_________\n');
+ console.log(err || container2);
+
+ waz.blobs.container.list(function(err, containers) {
+ console.log('\n_________| listing existing containers |_________\n');
+ console.log(containers || err.message);
+
+ containers[0].putMetadata({'x-ms-meta-Custom' : 'MyValue'}, function(err) {
+ console.log(err || '`x-ms-meta-Custom` metadata added!');
+
+ containers[0].metadata(function(err, metadata) {
+ console.log('\n_________| showing container metadata |_________\n');
+ console.log(err || metadata);
+ });
+ });
- // Finding a container
- waz.blobs.container.find('myContainer', function(err, container){
+ waz.blobs.container.find('container1', function(err, container1) {
+ console.log('\n_________| finding a container |_________\n');
+ console.log(err || container1);
- // Getting container's metadata
- container.metadata(function(err, metadata){
- });
-
- // Getting container's properties
- container.properties(function(err, properties){
- });
+ container1.blobs(function(err, blobs) {
+ console.log('\n_________| listing container blobs |_________\n');
+ console.log(err || blobs)
+ });
+
+ container1.setAcl('container', function(err, container) {
+ console.log('\n_________| setting container acl to `container` |_________\n');
+ console.log(err || 'container acl set to `container`');
+
+ container.getAcl(function(err, acl) {
+ console.log('\n_________| displaying container acl |_________\n');
+ console.log(err || acl);
+ });
+ });
+
+ console.log('\n_________| uploading a blob using blocks |_________\n');
+
+ var fs = require('fs');
+ var stream = fs.createReadStream('./test/mock-files/sample.txt', { 'flags': 'r' , mode: 0666, 'encoding': 'utf-8', 'bufferSize': 5 });
- // Adding metadata to a container
- container.putMetadata({'x-ms-custom' : 'MyValue'}, function(err){
- });
-
- // Getting container's ACL
- container.getAcl(function(err, acl){
- });
-
- // Setting container's ACL (null, 'blob', 'container')
- container.setAcl('container', function(err, container){
- });
-
- // Listing blobs in a container
- container.blobs(function(err, blobs){
- });
-
- // Getting blob's information
- result.getBlob('myfolder/my file.txt', function(err, blob){
+ var uploader = container1.upload('myBlockBlob', stream, "plain/text", {'x-ms-mymetadata': 'value'}, function(err, block) {
+ console.log('\n_________| block uploaded |_________\n');
+ console.log('blockid:' + block.identifier);
+ console.log('block#:' + block.number);
+
+ }, function(err, blob) {
+ console.log('\n_________| block list submitted |_________\n');
+ console.log(blob);
- // Adding metadata to a blob
- blob.putMetadata({'x-ms-custom' : 'MyValue'}, function(err){
- });
+ blob.getContents(function(err, contents) {
+ console.log(contents);
+ blob.destroy(function(err) {});
+ });
+ });
- // Getting blob's metadata
- blob.metadata(function(err, metadata){
- });
-
- // Adding properties to a blob
- blob.putProperties({'x-ms-blob-property1': 'MyValue'}, function(err, properties){
- });
-
- // Getting blob's properties
- blob.properties(function(err, properties){
- });
+ container1.store('Folder/hello world.xml', '<xml/>', 'text/xml', {'x-ms-test': 'myvalue'}, function(err, helloWorldBlob) {
+ console.log('\n_________| storing a new blob |_________\n');
+ console.log(err || helloWorldBlob);
- // Creating a snapshot of a blob
- blob.snapshot(function(err, blob){
- console.log(blob.snapshotDate);
- });
-
- // Getting blob's contents
- blob.getContents(function(err, data){
-
- blob.metadata = {'x-ms-custom-medatada': 'value'};
- blob.contentType = 'text/css';
-
- // Updating blob's contents
- blob.updateContents('new-content', function(err, blob){
- // Copying a blob
- blob.copy('container/newFolder/my file_copy.txt', function(err, newBlob){
- });
-
- // Removing a blob
- blob.destroy(function(err){
+ container1.getBlob('Folder/hello world.xml', function(err, blob) {
+ console.log('\n_________| getting a blob |_________\n');
+ console.log(err || blob);
+
+ blob.getContents(function(err,data) {
+ console.log('\n_________| displaying blob contents |_________\n');
+ console.log(err || data);
+ });
+
+ blob.copy('container2/Folder/helloCopy.xml', function(err, newBlob) {
+ console.log('\n_________| copying a blob |_________\n');
+ console.log(err || newBlob);
+ });
+
+ blob.snapshot(function(err, blob) {
+ console.log('\n_________| creating a snapshot of a blob |_________\n');
+ console.log(err || blob.snapshotDate);
+ });
+
+ blob.putMetadata({'x-ms-meta-custom': 'value'}, function(err) {
+ console.log('\n_________| adding metadata to the blob |_________\n');
+ console.log(err || '`x-ms-meta-custom` metadata added');
+
+ blob.metadata(function(err, metadata) {
+ console.log('\n_________| displaying blob metadata |_________\n');
+ console.log(err || metadata);
+
+ blob.putProperties({'x-ms-blob-custom': 'value'}, function(err) {
+ console.log('\n_________| adding a property to the blob |_________\n');
+ console.log(err || '`x-ms-blob-custom` property added!');
+
+ blob.properties(function(err, properties) {
+ console.log('\n_________| displaying blob properties |_________\n');
+ console.log(err || properties);
+
+ blob.contentType = 'newContentType'
+ blob.metadata = {'x-ms-new-metadata': 'value'};
+ console.log(blob);
+
+ blob.updateContents('new-content', function(err, updatedBlob) {
+ console.log('\n_________| updating blob contents |_________\n');
+ console.log(err || updatedBlob.requestId);
+ updatedBlob.destroy(function(err) {
+ console.log('\n_________| destroying a blob |_________\n');
+ console.log(err || 'blob `' + updatedBlob.path + '` removed!');
+
+ waz.blobs.container.delete('container1', function(err) {
+ console.log('\n_________| removing a container |_________\n');
+ console.log(err || '`container1` container removed!');
+ });
+
+ waz.blobs.container.delete('container2', function(err) {
+ console.log('\n_________| removing a container |_________\n');
+ console.log(err || '`container2` container removed!');
+ });
+ });
+ });
+ });
+ });
+ });
+ });
});
});
});
});
-
- // Storing a new Blob
- result.store('folder/my file.xml', '<xml>content</xml>', 'text/xml', {'x-ms-MyProperty': 'value'}, function(err, result){
- });
- }
- });
-
- // Deleting containers
- waz.blobs.container.delete('myContainer', function(err){
+ });
});
## Queues
@@ -119,7 +163,9 @@ To install via npm
* Documentation
## Blobs
-* Blocks
+* Upload blocks and submit block list separately
+* Put Page and Get Page Regions
+* Download blobs and persist them as stream in addition to blob.getContents()
## Queues
* Everything
View
@@ -2,101 +2,122 @@ var waz = require('waz-storage-js');
waz.establishConnection( { accountName: 'your_account_name', accountKey: 'your_account_key', useSsl: false } );
-waz.blobs.container.create('container1', function(err, container1){
+waz.blobs.container.create('container1', function(err, container1) {
console.log('\n_________| creating a container |_________\n');
console.log(err || container1);
- waz.blobs.container.create('container2', function(err, container2){
+ waz.blobs.container.create('container2', function(err, container2) {
console.log('\n_________| creating another container |_________\n');
console.log(err || container2);
- waz.blobs.container.list(function(err, containers){
+ waz.blobs.container.list(function(err, containers) {
console.log('\n_________| listing existing containers |_________\n');
console.log(containers || err.message);
- containers[0].putMetadata({'x-ms-meta-Custom' : 'MyValue'}, function(err){
+ containers[0].putMetadata({'x-ms-meta-Custom' : 'MyValue'}, function(err) {
console.log(err || '`x-ms-meta-Custom` metadata added!');
- containers[0].metadata(function(err, metadata){
+ containers[0].metadata(function(err, metadata) {
console.log('\n_________| showing container metadata |_________\n');
console.log(err || metadata);
});
});
- waz.blobs.container.find('container1', function(err, container1){
+ waz.blobs.container.find('container1', function(err, container1) {
console.log('\n_________| finding a container |_________\n');
console.log(err || container1);
- container1.blobs(function(err, blobs){
+ container1.blobs(function(err, blobs) {
console.log('\n_________| listing container blobs |_________\n');
console.log(err || blobs)
});
- container1.setAcl('container', function(err, container){
+ container1.setAcl('container', function(err, container) {
console.log('\n_________| setting container acl to `container` |_________\n');
console.log(err || 'container acl set to `container`');
- container.getAcl(function(err, acl){
+ container.getAcl(function(err, acl) {
console.log('\n_________| displaying container acl |_________\n');
console.log(err || acl);
});
});
- container1.store('Folder/hello world.xml', '<xml/>', 'text/xml', {'x-ms-test': 'myvalue'}, function(err, helloWorldBlob){
+ console.log('\n_________| uploading a blob using blocks |_________\n');
+
+ var fs = require('fs');
+ var stream = fs.createReadStream('./test/mock-files/sample.txt', { 'flags': 'r' , mode: 0666, 'encoding': 'utf-8', 'bufferSize': 5 });
+
+ var uploader = container1.upload('myBlockBlob', stream, "plain/text", {'x-ms-mymetadata': 'value'}, function(err, block) {
+ console.log('\n_________| block uploaded |_________\n');
+ console.log('blockid:' + block.identifier);
+ console.log('block#:' + block.number);
+
+ }, function(err, blob) {
+ console.log('\n_________| block list submitted |_________\n');
+ console.log(blob);
+
+ blob.getContents(function(err, contents) {
+ console.log(contents);
+ blob.destroy(function(err) {});
+ });
+ });
+
+ container1.store('Folder/hello world.xml', '<xml/>', 'text/xml', {'x-ms-test': 'myvalue'}, function(err, helloWorldBlob) {
console.log('\n_________| storing a new blob |_________\n');
console.log(err || helloWorldBlob);
- container1.getBlob('Folder/hello world.xml', function(err, blob){
+ container1.getBlob('Folder/hello world.xml', function(err, blob) {
console.log('\n_________| getting a blob |_________\n');
console.log(err || blob);
- blob.copy('container2/Folder/helloCopy.xml', function(err, newBlob){
+ blob.getContents(function(err,data) {
+ console.log('\n_________| displaying blob contents |_________\n');
+ console.log(err || data);
+ });
+
+ blob.copy('container2/Folder/helloCopy.xml', function(err, newBlob) {
console.log('\n_________| copying a blob |_________\n');
console.log(err || newBlob);
});
- blob.snapshot(function(err, blobWithSnapshot){
+ blob.snapshot(function(err, blob) {
console.log('\n_________| creating a snapshot of a blob |_________\n');
- console.log(err || blobWithSnapshot.snapshotDate);
- });
-
- blob.getContents(function(err,data){
- console.log('\n_________| displaying blob contents |_________\n');
- console.log(err || data);
+ console.log(err || blob.snapshotDate);
});
blob.putMetadata({'x-ms-meta-custom': 'value'}, function(err) {
console.log('\n_________| adding metadata to the blob |_________\n');
console.log(err || '`x-ms-meta-custom` metadata added');
- blob.metadata(function(err, metadata){
+ blob.metadata(function(err, metadata) {
console.log('\n_________| displaying blob metadata |_________\n');
console.log(err || metadata);
blob.putProperties({'x-ms-blob-custom': 'value'}, function(err) {
console.log('\n_________| adding a property to the blob |_________\n');
console.log(err || '`x-ms-blob-custom` property added!');
- blob.properties(function(err, properties){
+ blob.properties(function(err, properties) {
console.log('\n_________| displaying blob properties |_________\n');
console.log(err || properties);
blob.contentType = 'newContentType'
blob.metadata = {'x-ms-new-metadata': 'value'};
console.log(blob);
- blob.updateContents('new-content', function(err, updatedBlob){
+
+ blob.updateContents('new-content', function(err, updatedBlob) {
console.log('\n_________| updating blob contents |_________\n');
console.log(err || updatedBlob.requestId);
- updatedBlob.destroy(function(err){
+ updatedBlob.destroy(function(err) {
console.log('\n_________| destroying a blob |_________\n');
console.log(err || 'blob `' + updatedBlob.path + '` removed!');
- waz.blobs.container.delete('container1', function(err){
+ waz.blobs.container.delete('container1', function(err) {
console.log('\n_________| removing a container |_________\n');
console.log(err || '`container1` container removed!');
});
- waz.blobs.container.delete('container2', function(err){
+ waz.blobs.container.delete('container2', function(err) {
console.log('\n_________| removing a container |_________\n');
console.log(err || '`container2` container removed!');
});
Oops, something went wrong.

0 comments on commit ca735b1

Please sign in to comment.