-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContainer.js
More file actions
97 lines (78 loc) · 2.63 KB
/
Container.js
File metadata and controls
97 lines (78 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var P = require('bluebird');
var _ = require('lodash');
var azure = require('azure-storage');
var fs = P.promisifyAll(require("fs"));
var path = require('path');
function Container(accountName, accountKey, containerName) {
this.name = containerName;
this.service = azure.createBlobService(accountName, accountKey);
}
var listAllHelper = function(container, entries, continuationToken) {
entries = entries || [];
return container.listBlobs(continuationToken).then(function(result) {
// push all the new entries
Array.prototype.push.apply(entries, result.entries);
// fetch the next set of entries
if (result.continuationToken) {
return listAllHelper(container, entries, result.continuationToken);
}
// otherwise return full set of entries
return entries;
});
};
Container.prototype.listAllBlobs = function() {
return listAllHelper(this, [], null);
};
Container.prototype.listBlobs = function(continuationToken) {
return new P(_.bind(function (resolve, reject) {
this.service.listBlobsSegmented(this.name, continuationToken,
function(error, result, response){
if (error){
reject(error);
} else {
resolve(result);
}
}
);
}, this));
};
Container.prototype.getBlobText = function(blobName) {
return new P(_.bind(function (resolve, reject) {
this.service.getBlobToText(this.name, blobName,
function(error, blobContent, blob){
if (error){
reject(error);
} else {
resolve(blobContent);
}
}
);
}, this));
};
Container.prototype.getBlobToFile = function(blobName, localFileName, options) {
return new P(_.bind(function (resolve, reject) {
this.service.getBlobToLocalFile(this.name, blobName, localFileName, options,
function(error, blockBlob, response) {
if (error){
reject(error);
} else {
resolve(blockBlob);
}
}
);
}, this));
};
Container.prototype.getBlobProperties = function (blobName, options) {
return new P(_.bind(function (resolve, reject) {
this.service.getBlobProperties(this.name, blobName, options,
function(error, blob, response) {
if (error){
reject(error);
} else {
resolve(blob);
}
}
);
}, this));
};
module.exports = Container;