Skip to content

Commit

Permalink
Merge pull request #114 from hasonmsft/master
Browse files Browse the repository at this point in the history
Storage Client Library 0.8.0
  • Loading branch information
vinjiang committed Jan 28, 2016
2 parents f548c06 + 544b20a commit 3b62207
Show file tree
Hide file tree
Showing 12 changed files with 29,331 additions and 19 deletions.
9 changes: 9 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Note: This is an Azure Storage only package. The all up Azure node sdk still has the old storage bits in there. In a future release, those storage bits will be removed and an npm dependency to this storage node sdk will
be taken. This is a CTP v1 release and the changes described below indicate the changes from the Azure node SDK 0.9.8 available here - https://github.com/Azure/azure-sdk-for-node.

2016.01 Version 0.8.0

ALL
* Preview release of the TypeScript definition file at "lib/azure-storage.d.ts".

BLOB
* Added the blob result to the callback of BlobService.commitBlocks.
* Added the speed summary to the downloading APIs.

2015.12 Version 0.7.0

ALL
Expand Down
8,313 changes: 8,313 additions & 0 deletions lib/azure-storage.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/common/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Constants = {
/*
* Specifies the value to use for UserAgent header.
*/
USER_AGENT_PRODUCT_VERSION: '0.7.0',
USER_AGENT_PRODUCT_VERSION: '0.8.0',

/**
* The number of default concurrent requests for parallel operation.
Expand Down
38 changes: 25 additions & 13 deletions lib/services/blob/blobservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ BlobService.prototype.setBlobMetadata = function (container, blob, metadata, opt
* @param {boolean} [options.skipSizeCheck] Skip the size check to perform direct download.
* Set the option to true for small blobs.
* Parallel download and speed summary won't work with this option on.
* @param {SpeedSummary} [options.speedSummary] The upload tracker objects.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {int} [options.parallelOperationThreadCount] Parallel operation thread count
* @param {string} [options.snapshotId] The snapshot identifier.
* @param {string} [options.leaseId] The lease identifier.
Expand Down Expand Up @@ -1620,6 +1620,7 @@ BlobService.prototype.createReadStream = function (container, blob, optionsOrCal
* @param {boolean} [options.skipSizeCheck] Skip the size check to perform direct download.
* Set the option to true for small blobs.
* Parallel download and speed summary won't work with this option on.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {string} [options.snapshotId] The snapshot identifier.
* @param {string} [options.leaseId] The lease identifier.
* @param {string} [options.rangeStart] Return only the bytes of the blob in the specified range.
Expand All @@ -1639,6 +1640,7 @@ BlobService.prototype.createReadStream = function (container, blob, optionsOrCal
* @param {errorOrResult} callback `error` will contain information if an error occurs;
* otherwise `result` will contain the blob information.
* `response` will contain information related to this operation.
* @return {SpeedSummary}
*
* @example
* var azure = require('azure-storage');
Expand All @@ -1652,7 +1654,8 @@ BlobService.prototype.createReadStream = function (container, blob, optionsOrCal
BlobService.prototype.getBlobToStream = function (container, blob, writeStream, optionsOrCallback, callback) {
var userOptions;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { userOptions = o; callback = c; });

userOptions.speedSummary = userOptions.speedSummary || new SpeedSummary(blob);

validate.validateArgs('getBlobToStream', function (v) {
v.string(container, 'container');
v.string(blob, 'blob');
Expand Down Expand Up @@ -1685,6 +1688,8 @@ BlobService.prototype.getBlobToStream = function (container, blob, writeStream,
} else {
size = properties.contentLength;
}
options.speedSummary.totalSize = size;

if (size > self.singleBlobPutThresholdInBytes) {
options.contentMD5 = properties.contentMD5;
self._getBlobToRangeStream(container, blob, properties.blobType, writeStream, options, callback);
Expand Down Expand Up @@ -3162,7 +3167,7 @@ BlobService.prototype._createBlock = function (blockId, container, blob, content
* The default value is false.
* @param {errorOrResult} callback `error` will contain information
* if an error occurs; otherwise `result` will contain
* the blocklist information.
* the blob result with the blocklist information.
* `response` will contain information related to this operation.
*/
BlobService.prototype.commitBlocks = function (container, blob, blockList, optionsOrCallback, callback) {
Expand All @@ -3188,13 +3193,15 @@ BlobService.prototype.commitBlocks = function (container, blob, blockList, optio
BlobResult.setPropertiesFromBlob(webResource, options);

var processResponseCallback = function (responseObject, next) {
responseObject.list = null;
responseObject.blobResult = new BlobResult(container, blob);
responseObject.blobResult.list = null;
if (!responseObject.error) {
responseObject.list = blockList;
responseObject.blobResult.getPropertiesFromHeaders(responseObject.response.headers);
responseObject.blobResult.list = blockList;
}

var finalCallback = function (returnObject) {
callback(returnObject.error, returnObject.list, returnObject.response);
callback(returnObject.error, returnObject.blobResult, returnObject.response);
};

next(responseObject, finalCallback);
Expand Down Expand Up @@ -3909,7 +3916,7 @@ BlobService.prototype._createBlobFromLocalFile = function (container, blob, blob
self._uploadBlobFromStream(true, container, blob, blobType, stream, size, options, streamCallback);
}
};

// Check the file size to determine the upload method: single request or chunks
fs.stat(localFileName, function (error, stat) {
if (error) {
Expand Down Expand Up @@ -5172,15 +5179,15 @@ BlobService.prototype._setRangeContentMD5Header = function (webResource, options
};

/**
* Downloads a blockblob or pageblob into a range stream.
* Downloads a blockblob, pageblob or appendblob into a range stream.
* @ignore
* @this {BlobService}
* @param {string} container The container name.
* @param {string} blob The blob name.
* @param {string} blobType The type of blob to create: block blob or page blob.
* @param {string} blobType The type of blob to download: block blob, page blob or append blob.
* @param {Stream} writeStream The write stream.
* @param {object} [options] The request options.
* @param {SpeedSummary} [options.speedSummary] The upload tracker objects.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {int} [options.parallelOperationThreadCount] Parallel operation thread count
* @param {string} [options.snapshotId] The snapshot identifier.
* @param {string} [options.leaseId] The lease identifier.
Expand Down Expand Up @@ -5446,6 +5453,7 @@ BlobService.prototype._getBlobToStream = function (container, blob, writeStream,
* @param {boolean} [options.skipSizeCheck] Skip the size check to perform direct download.
* Set the option to true for small blobs.
* Parallel download and speed summary won't work with this option on.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {string} [options.snapshotId] The snapshot identifier.
* @param {string} [options.leaseId] The lease identifier.
* @param {string} [options.rangeStart] Return only the bytes of the blob in the specified range.
Expand All @@ -5465,11 +5473,14 @@ BlobService.prototype._getBlobToStream = function (container, blob, writeStream,
* @param {errorOrResult} callback `error` will contain information if an error occurs;
* otherwise `result` will contain the blob information.
* `response` will contain information related to this operation.
* @return {SpeedSummary}
*
*/
BlobService.prototype._getBlobToLocalFile = function (container, blob, localFileName, optionsOrCallback, callback) {
var options;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });

options.speedSummary = options.speedSummary || new SpeedSummary(blob);

var writeStream = fs.createWriteStream(localFileName, { 'highWaterMark': BlobConstants.MAX_QUEUED_WRITE_DISK_BUFFER_SIZE });

this.getBlobToStream(container, blob, writeStream, options, function (error, responseBlob, response) {
Expand All @@ -5484,12 +5495,13 @@ BlobService.prototype._getBlobToLocalFile = function (container, blob, localFile
fs.unlink(localFileName, function () {
callback(error, responseBlob, response);
});

return;
}
}
callback(error, responseBlob, response);
});
});

return options.speedSummary;
};

/**
Expand Down
16 changes: 14 additions & 2 deletions lib/services/file/fileservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,7 @@ FileService.prototype.getFileToText = function (share, directory, file, optionsO
* @param {boolean} [options.skipSizeCheck] Skip the size check to perform direct download.
* Set the option to true for small files.
* Parallel download and speed summary won't work with this option on.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {string} [options.rangeStart] Return only the bytes of the file in the specified range.
* @param {string} [options.rangeEnd] Return only the bytes of the file in the specified range.
* @param {boolean} [options.useTransactionalMD5] When set to true, Calculate and send/validate content MD5 for transactions.
Expand All @@ -2192,6 +2193,8 @@ FileService.prototype.getFileToText = function (share, directory, file, optionsO
* @param {errorOrResult} callback `error` will contain information if an error occurs;
* otherwise `result` will contain the file information.
* `response` will contain information related to this operation.
* @return {SpeedSummary}
*
* @example
* var azure = require('azure-storage');
* var FileService = azure.createFileService();
Expand All @@ -2203,6 +2206,7 @@ FileService.prototype.getFileToText = function (share, directory, file, optionsO
FileService.prototype.getFileToLocalFile = function (share, directory, file, localFileName, optionsOrCallback, callback) {
var userOptions;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { userOptions = o; callback = c; });
userOptions.speedSummary = userOptions.speedSummary || new SpeedSummary(file);

validate.validateArgs('getFileToLocalFile', function (v) {
v.string(share, 'share');
Expand Down Expand Up @@ -2234,6 +2238,8 @@ FileService.prototype.getFileToLocalFile = function (share, directory, file, loc
}
callback(error, responseFile, response);
});

return options.speedSummary;
};

/**
Expand Down Expand Up @@ -2306,6 +2312,7 @@ FileService.prototype.createReadStream = function (share, directory, file, optio
* @param {boolean} [options.skipSizeCheck] Skip the size check to perform direct download.
* Set the option to true for small files.
* Parallel download and speed summary won't work with this option on.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects.
* @param {string} [options.rangeStart] Return only the bytes of the file in the specified range.
* @param {string} [options.rangeEnd] Return only the bytes of the file in the specified range.
* @param {boolean} [options.useTransactionalMD5] When set to true, Calculate and send/validate content MD5 for transactions.
Expand All @@ -2322,6 +2329,8 @@ FileService.prototype.createReadStream = function (share, directory, file, optio
* @param {errorOrResult} callback `error` will contain information if an error occurs;
* otherwise `result` will contain the file information.
* `response` will contain information related to this operation.
* @return {SpeedSummary}
*
*
* @example
* var azure = require('azure-storage');
Expand All @@ -2335,7 +2344,8 @@ FileService.prototype.createReadStream = function (share, directory, file, optio
FileService.prototype.getFileToStream = function (share, directory, file, writeStream, optionsOrCallback, callback) {
var userOptions;
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { userOptions = o; callback = c; });

userOptions.speedSummary = userOptions.speedSummary || new SpeedSummary(file);

validate.validateArgs('getFileToStream', function (v) {
v.string(share, 'share');
v.stringAllowEmpty(directory, 'directory');
Expand Down Expand Up @@ -2368,6 +2378,8 @@ FileService.prototype.getFileToStream = function (share, directory, file, writeS
} else {
size = properties.contentLength;
}
options.speedSummary.totalSize = size;

if (size > self.singleFileThresholdInBytes) {
options.contentMD5 = properties.contentMD5;
self._getFileToRangeStream(share, directory, file, writeStream, options, callback);
Expand Down Expand Up @@ -2585,7 +2597,7 @@ FileService.prototype.createRangesFromStream = function (share, directory, file,
* @param {string} file The file name. File names may not start or end with the delimiter '/'.
* @param {string|object} text The file text, as a string or in a Buffer.
* @param {object} [options] The request options.
* @param {SpeedSummary} [options.speedSummary] The download tracker objects;
* @param {SpeedSummary} [options.speedSummary] The upload tracker objects;
* @param {object} [options.metadata] The metadata key/value pairs.
* @param {bool} [options.storeFileContentMD5] Specifies whether the file's ContentMD5 header should be set on uploads.
* The default value is false for files.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "azure-storage",
"author": "Microsoft Corporation",
"version": "0.7.0",
"version": "0.8.0",
"description": "Microsoft Azure Storage Client Library for Node.js",
"tags": [
"azure",
Expand Down
44 changes: 42 additions & 2 deletions test/services/blob/blobservice-uploaddownload-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,14 @@ describe('blob-uploaddownload-tests', function () {
UncommittedBlocks: ['id2']
};

blobService.commitBlocks(containerName, blobName, blockList, function (error4) {
blobService.commitBlocks(containerName, blobName, blockList, function (error4, blob) {
assert.equal(error4, null);
assert.equal(blob.container, containerName);
assert.equal(blob.blob, blobName);
assert.deepEqual(blob.list, blockList);
assert.notEqual(blob.etag, null);
assert.notEqual(blob.lastModified, null);
assert.notEqual(blob.contentMD5, null);

blobService.listBlocks(containerName, blobName, BlobUtilities.BlockListFilter.ALL, function (error5, list) {
assert.equal(error5, null);
Expand Down Expand Up @@ -674,8 +680,14 @@ describe('blob-uploaddownload-tests', function () {
LatestBlocks: ['id1'],
};

blobService.commitBlocks(containerName, blobName, blockList, function (error4) {
blobService.commitBlocks(containerName, blobName, blockList, function (error4, blob) {
assert.equal(error4, null);
assert.equal(blob.container, containerName);
assert.equal(blob.blob, blobName);
assert.deepEqual(blob.list, blockList);
assert.notEqual(blob.etag, null);
assert.notEqual(blob.lastModified, null);
assert.notEqual(blob.contentMD5, null);

blobService.listBlocks(containerName, blobName, BlobUtilities.BlockListFilter.ALL, function (error5, list) {
assert.equal(error5, null);
Expand Down Expand Up @@ -1250,6 +1262,34 @@ describe('blob-uploaddownload-tests', function () {
});
});
});

runOrSkip('getBlobToLocalFile should return the SpeedSummary correctly', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlobToLocalFileSpeedSummary', [], suite.isMocked) + '.test';
var fileSize = 97 * 1024 * 1024; // Don't be a multiple of 4MB to cover more scenarios
generateTempFile(fileNameSource, fileSize, false, function (fileInfo) {
uploadOptions.parallelOperationThreadCount = 5;
blobService.createBlockBlobFromLocalFile(containerName, blobName, fileNameSource, uploadOptions, function (error) {
assert.equal(error, null);

var speedSummary;
var downloadOptions = {
parallelOperationThreadCount : 5
};

speedSummary = blobService.getBlobToLocalFile(containerName, blobName, fileNameSource, downloadOptions, function (error) {
assert.equal(speedSummary.getTotalSize(false), fileSize);
assert.equal(speedSummary.getCompleteSize(false), fileSize);
assert.equal(speedSummary.getCompletePercent(), '100.0');

try { fs.unlinkSync(fileNameSource); } catch (e) { }
done();
});

assert.notEqual(speedSummary, null);
});
});
});

runOrSkip('should have same md5 with range-based downloading to stream', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
Expand Down
Loading

0 comments on commit 3b62207

Please sign in to comment.