Remove deprecated Buffer constructor calls

Replace with static methods `Buffer.from` and `Buffer.alloc`
This commit is contained in:
Suz Hinton 2018-09-28 13:28:13 -07:00 коммит произвёл Vincent Jiang (LEI)
Родитель 3dd857b905
Коммит fd1e656680
25 изменённых файлов: 109 добавлений и 103 удалений

Просмотреть файл

@ -1,6 +1,12 @@
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 GA 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.
2018.09 Version 2.10.2
ALL
* Removed deprecated Buffer constructor calls in favor of static methods `Buffer.from` and `Buffer.alloc`
2018.08 Version 2.10.1
ALL

Просмотреть файл

@ -356,7 +356,7 @@ StorageServiceClient.prototype._performRequest = function (webResource, body, op
var errorMessageBuffer;
var index = 0;
if (contentLength !== undefined) {
errorMessageBuffer = new Buffer(contentLength);
errorMessageBuffer = Buffer.alloc(contentLength);
}
requestStream.on('data', function (data) {
@ -478,7 +478,7 @@ StorageServiceClient.prototype._performRequest = function (webResource, body, op
finalRequestOptions.headers['content-length'] :
Constants.BlobConstants.MAX_SINGLE_UPLOAD_BLOB_SIZE_IN_BYTES;
var concatBuf = new Buffer(size);
var concatBuf = Buffer.alloc(parseInt(size));
var index = 0;
body.outputStream.on('data', function (d) {

Просмотреть файл

@ -42,7 +42,7 @@ ChunkAllocator.prototype.getBuffer = function(size) {
if (buffer === null) {
// Either the total memory is larger than this._chunkSize * this._maxCount
// Or, the size does not match the chunk size of the pool
buffer = new Buffer(size);
buffer = Buffer.alloc(size);
}
this._inuse++;
@ -86,7 +86,7 @@ ChunkAllocator.prototype._extendMemoryPool = function() {
// Add more buffers.
var increment = nextSize - total;
for(var i = 0; i < increment; i++) {
var buffer = new Buffer(this._chunkSize);
var buffer = Buffer.alloc(this._chunkSize);
this._pool.push(buffer);
}
};

Просмотреть файл

@ -148,7 +148,7 @@ ChunkStream.prototype.write = function (chunk, encoding) {
*/
ChunkStream.prototype._buildChunk = function (data) {
if (typeof data == 'string') {
data = new Buffer(data);
data = Buffer.from(data);
}
var dataSize = data.length;
var dataOffset = 0;
@ -276,7 +276,7 @@ ChunkStream.prototype._allocateNewBuffer = function() {
if(this._allocator && azureutil.objectIsFunction(this._allocator.getBuffer)) {
return this._allocator.getBuffer(size);
} else {
var buffer = new Buffer(size);
var buffer = Buffer.alloc(size);
return buffer;
}
};

Просмотреть файл

@ -105,7 +105,7 @@ FileReadStream.prototype._getBuffer = function(size) {
if(this._allocator && this._allocator.getBuffer) {
return this._allocator.getBuffer(size);
} else {
var buffer = new Buffer(size);
var buffer = Buffer.alloc(size);
return buffer;
}
};

Просмотреть файл

@ -388,7 +388,7 @@ exports.getNodeVersion = function () {
* @ignore
*/
exports.calculateMD5 = function(readStream, bufferLength, options, callback) {
var internalBuff = new Buffer(bufferLength);
var internalBuff = Buffer.alloc(bufferLength);
var index = 0;
var internalHash = new Md5Wrapper().createMd5Hash();
readStream.on('data', function(data) {
@ -441,12 +441,12 @@ exports.writeZerosToStream = function (stream, length, md5Hash, progressCallback
var buffer = null;
if (bufferSize == defaultBufferSize) {
if (!zeroBuffer) {
zeroBuffer = new Buffer(defaultBufferSize);
zeroBuffer = Buffer.alloc(defaultBufferSize);
zeroBuffer.fill(0);
}
buffer = zeroBuffer;
} else {
buffer = new Buffer(bufferSize);
buffer = Buffer.alloc(bufferSize);
buffer.fill(0);
}
if (md5Hash) {

Просмотреть файл

@ -3402,7 +3402,7 @@ BlobService.prototype.createBlockFromURL = function (blockId, container, blob, s
var webResource = WebResource.put(resourceName)
.withQueryOption(QueryStringConstants.COMP, 'block')
.withQueryOption(QueryStringConstants.BLOCK_ID, new Buffer(blockId).toString('base64'))
.withQueryOption(QueryStringConstants.BLOCK_ID, Buffer.from(blockId).toString('base64'))
.withHeader(HeaderConstants.COPY_SOURCE, sourceURL);
options.sourceRangeStart = sourceRangeStart;
@ -3457,7 +3457,7 @@ BlobService.prototype._createBlock = function (blockId, container, blob, content
var startCreateBlock = function () {
var webResource = WebResource.put(resourceName)
.withQueryOption(QueryStringConstants.COMP, 'block')
.withQueryOption(QueryStringConstants.BLOCK_ID, new Buffer(blockId).toString('base64'))
.withQueryOption(QueryStringConstants.BLOCK_ID, Buffer.from(blockId).toString('base64'))
.withHeader(HeaderConstants.CONTENT_LENGTH, length);
BlobResult.setHeadersFromBlob(webResource, options);

Просмотреть файл

@ -34,7 +34,7 @@ exports.serialize = function (blockListJs) {
if (_.isArray(blockListJs.LatestBlocks)) {
blockListJs.LatestBlocks.forEach(function (block) {
blockListDoc = blockListDoc.ele(Constants.BlobConstants.LATEST_ELEMENT)
.txt(new Buffer(block).toString('base64'))
.txt(Buffer.from(block).toString('base64'))
.up();
});
}
@ -42,7 +42,7 @@ exports.serialize = function (blockListJs) {
if (_.isArray(blockListJs.CommittedBlocks)) {
blockListJs.CommittedBlocks.forEach(function (block) {
blockListDoc = blockListDoc.ele(Constants.BlobConstants.COMMITTED_ELEMENT)
.txt(new Buffer(block).toString('base64'))
.txt(Buffer.from(block).toString('base64'))
.up();
});
}
@ -50,7 +50,7 @@ exports.serialize = function (blockListJs) {
if (_.isArray(blockListJs.UncommittedBlocks)) {
blockListJs.UncommittedBlocks.forEach(function (block) {
blockListDoc = blockListDoc.ele(Constants.BlobConstants.UNCOMMITTED_ELEMENT)
.txt(new Buffer(block).toString('base64'))
.txt(Buffer.from(block).toString('base64'))
.up();
});
}
@ -67,7 +67,7 @@ exports.parse = function (blockListXml) {
blockListResult.CommittedBlocks = [blockListResult.CommittedBlocks];
}
blockListResult.CommittedBlocks.forEach(function(block) {
block.Name = new Buffer(block.Name, 'base64').toString();
block.Name = Buffer.from(block.Name, 'base64').toString();
});
}
@ -77,7 +77,7 @@ exports.parse = function (blockListXml) {
blockListResult.UncommittedBlocks = [blockListResult.UncommittedBlocks];
}
blockListResult.UncommittedBlocks.forEach(function(block) {
block.Name = new Buffer(block.Name, 'base64').toString();
block.Name = Buffer.from(block.Name, 'base64').toString();
});
}

Просмотреть файл

@ -74,7 +74,7 @@ util.inherits(TextBase64QueueMessageEncoder, QueueMessageEncoder);
* @return {string}
*/
TextBase64QueueMessageEncoder.prototype.encode = function(input){
return new Buffer(input, 'utf8').toString('base64');
return Buffer.from(input, 'utf8').toString('base64');
};
/**
@ -86,7 +86,7 @@ TextBase64QueueMessageEncoder.prototype.encode = function(input){
* @return {string}
*/
TextBase64QueueMessageEncoder.prototype.decode = function(textToDecode){
return new Buffer(textToDecode, 'base64').toString('utf8');
return Buffer.from(textToDecode, 'base64').toString('utf8');
};
@ -126,7 +126,7 @@ BinaryBase64QueueMessageEncoder.prototype.encode = function(input){
* @return {Buffer}
*/
BinaryBase64QueueMessageEncoder.prototype.decode = function(textToDecode){
return new Buffer(textToDecode, 'base64');
return Buffer.from(textToDecode, 'base64');
};

Просмотреть файл

@ -65,7 +65,7 @@ exports.deserializeValueFromJson = function (type, value) {
if (type) {
switch (type) {
case EdmType.BINARY:
return new Buffer(value, 'base64');
return Buffer.from(value, 'base64');
case EdmType.DATETIME:
return new Date(value);
case EdmType.GUID:

Просмотреть файл

@ -170,7 +170,7 @@ exports.parseJsonSingleEntity = function(rawEntity, autoResolveProperties, prope
// make sure etag is set
if (!odataMetadata.etag && rawEntityProperties.Timestamp) {
var timestampString = new Buffer(rawEntityProperties.Timestamp).toString();
var timestampString = Buffer.from(rawEntityProperties.Timestamp).toString();
odataMetadata.etag = 'W/"datetime\'' + timestampString + '\'"';
}

Просмотреть файл

@ -210,7 +210,7 @@ TableQuery.guidFilter = function (propertyName, operation, value) {
* @param {string|buffer}value A 'buffer' containing the value to compare with the property.
* @return {string} A string containing the formatted filter condition.
* @example
* var query = TableQuery.binaryFilter('BinaryField', QueryComparisons.EQUAL, new Buffer('hello'));
* var query = TableQuery.binaryFilter('BinaryField', QueryComparisons.EQUAL, Buffer.from('hello'));
*/
TableQuery.binaryFilter = function (propertyName, operation, value) {
return TableQuery._concatFilterString(propertyName, operation, value, EdmType.BINARY);

Просмотреть файл

@ -925,7 +925,7 @@ var runFilesPermissionTests = function(sharedAccessPolicy, next){
var fileName = suite.getName("file-");
var localTempFileName = suite.getName('fileservice_test_block');
var fileSize = 100;
var fileBuffer = new Buffer( fileSize );
var fileBuffer = Buffer.alloc( fileSize );
fileBuffer.fill(1);
writeFile(localTempFileName, fileBuffer);

Просмотреть файл

@ -181,7 +181,7 @@ describe('exponentialretrypolicyfilter-tests', function () {
var fileSize = 100;
// Real stream length is smaller than the expected data length to mock the client timeout error to trigger the retry
var fileBuffer = new Buffer( fileSize / 2 );
var fileBuffer = Buffer.alloc( fileSize / 2 );
fileBuffer.fill(1);
fs.writeFileSync(localTempFileName, fileBuffer);

Просмотреть файл

@ -57,7 +57,7 @@ var blobNames = [];
var blobNamesPrefix = 'blob';
var fileName = 'blobservice_test.tmp';
var blob60MBuffer = new Buffer(80 * 1024 * 1024);
var blob60MBuffer = Buffer.alloc(80 * 1024 * 1024);
var suite = new TestSuite('blobservice-tests');
var runOrSkip = testutil.itSkipMock(suite.isMocked);
@ -374,7 +374,7 @@ describe('BlobService', function () {
it('withBuffer', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var blobText = new Buffer('Hello World');
var blobText = Buffer.from('Hello World');
blobService.createBlockBlobFromText(containerName, blobName, blobText, function (uploadError, blob, uploadResponse) {
assert.equal(uploadError, null);
@ -756,7 +756,7 @@ describe('BlobService', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlobFile', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(1024);
var blobBuffer = Buffer.alloc(1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
blobService.createPageBlob(containerName, blobName, 1024, function(createErr) {

Просмотреть файл

@ -197,7 +197,7 @@ describe('BlobServiceUploadDownloadScale', function () {
function generateTempFile(fileName, size, callback) {
var blockSize = 4 * 1024 * 1024;
if(!internalBuffer) {
internalBuffer = new Buffer(blockSize);
internalBuffer = Buffer.alloc(blockSize);
}
var md5hash = crypto.createHash('md5');
var fileInfo = {name: fileName, contentMD5: '', size: size};
@ -210,7 +210,7 @@ describe('BlobServiceUploadDownloadScale', function () {
content = internalBuffer;
size -= blockSize;
} else {
content = new Buffer(size);
content = Buffer.alloc(size);
size = 0;
}
if (content.length) {

Просмотреть файл

@ -63,10 +63,10 @@ var downloadName = 'blobservice_download.tmp';
var fileText = 'Hello World!';
var pageBlobBuffer = new Buffer(1 * 1024);
var pageBlob2KBuffer = new Buffer(2 * 1024);
var appendBlobBuffer = new Buffer(1 * 1024);
var appendBlob2KBuffer = new Buffer(2 * 1024);
var pageBlobBuffer = Buffer.alloc(1 * 1024);
var pageBlob2KBuffer = Buffer.alloc(2 * 1024);
var appendBlobBuffer = Buffer.alloc(1 * 1024);
var appendBlob2KBuffer = Buffer.alloc(2 * 1024);
var pageBlobContentMD5 = '';
var pageBlob2KContentMD5 = '';
@ -110,7 +110,7 @@ var generateTempFile = function (fileName, size, hasEmptyBlock, callback) {
var buffer;
if (zero) {
buffer = new Buffer(writeSize);
buffer = Buffer.alloc(writeSize);
buffer.fill(0);
} else {
buffer = crypto.randomBytes(writeSize);
@ -133,7 +133,7 @@ var generateTempFile = function (fileName, size, hasEmptyBlock, callback) {
var getFileMD5 = function (fileName, callback) {
var md5hash = crypto.createHash('md5');
var blockSize = 4 * 1024 * 1024;
var buffer = new Buffer(blockSize);
var buffer = Buffer.alloc(blockSize);
var offset = 0;
var bytesRead = 0;
var file = fs.openSync(fileName, 'r');
@ -290,7 +290,7 @@ describe('blob-uploaddownload-tests', function () {
skipMockAndBrowser('should be able to upload block blob from piped stream', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadBlockBlobPiping', [], suite.isMocked) + '.blocktest';
var blobBuffer = new Buffer( 6 * 1024 * 1024);
var blobBuffer = Buffer.alloc( 6 * 1024 * 1024);
blobBuffer.fill(1);
// Write file so that it can be piped
@ -314,7 +314,7 @@ describe('blob-uploaddownload-tests', function () {
skipMockAndBrowser('should be able to upload block blob from piped stream with IfNoneMatch:*', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadBlockBlobPiping', [], suite.isMocked) + '.blocktest';
var blobBuffer = new Buffer( 6 * 1024 * 1024);
var blobBuffer = Buffer.alloc( 6 * 1024 * 1024);
blobBuffer.fill(1);
// Write file so that it can be piped
@ -338,7 +338,7 @@ describe('blob-uploaddownload-tests', function () {
skipMockAndBrowser('should be able to upload pageblob from piped stream', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadPageBlobPiping', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer( 5 * 1024 * 1024 );
var blobBuffer = Buffer.alloc( 5 * 1024 * 1024 );
blobBuffer.fill(1);
// Write file so that it can be piped
@ -368,7 +368,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadPageBlobMD5Piping', [], suite.isMocked) + '.test';
var length = 3 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill(1);
blobService.createContainer(containerName, function (createError1, container1) {
@ -399,7 +399,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadAppendBlobMD5Piping', [], suite.isMocked) + '.test';
var length = 3 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill(1);
// Write file so that it can be piped
@ -440,7 +440,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('uploadPageBlobStreamPiping', [], suite.isMocked) + '.test';
var length = 6 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill(1);
// Write file so that it can be piped
@ -465,7 +465,7 @@ describe('blob-uploaddownload-tests', function () {
var sourceFileNameTarget = testutil.generateId('getBlobSourceFile', [], suite.isMocked) + '.test';
var destinationFileNameTarget = testutil.generateId('getBlobDestinationFile', [], suite.isMocked) + '.test';
var length = 5 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill(1);
fs.writeFileSync(sourceFileNameTarget, blobBuffer);
@ -498,7 +498,7 @@ describe('blob-uploaddownload-tests', function () {
var sourceFileNameTarget = testutil.generateId('getBlobSourceFile', [], suite.isMocked) + '.test';
var destinationFileNameTarget = testutil.generateId('getBlobDestinationFile', [], suite.isMocked) + '.test';
var length = 33 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill(1);
fs.writeFileSync(sourceFileNameTarget, blobBuffer);
@ -611,7 +611,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getPageRanges', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(512);
var blobBuffer = Buffer.alloc(512);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -696,12 +696,12 @@ describe('blob-uploaddownload-tests', function () {
var fileNameSource = testutil.generateId('getPageRangesDiff', [], suite.isMocked) + '.test';
var fileNameSourceUpdated = testutil.generateId('getPageRangesDiffUpdated', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(512);
var blobBuffer = Buffer.alloc(512);
blobBuffer.fill(0);
blobBuffer[0] = '1';
blobBuffer[1] = '1';
var blobBufferUpdated = new Buffer(512);
var blobBufferUpdated = Buffer.alloc(512);
blobBufferUpdated.fill(0);
blobBufferUpdated[0] = '1';
blobBufferUpdated[1] = '1';
@ -1055,7 +1055,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('MD5Validation', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(5 * 1024 * 1024);
var blobBuffer = Buffer.alloc(5 * 1024 * 1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -1100,7 +1100,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlockBlobFileMD5', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(5 * 1024 * 1024);
var blobBuffer = Buffer.alloc(5 * 1024 * 1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -1146,7 +1146,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getPageBlobMD5', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(5 * 1024 * 1024);
var blobBuffer = Buffer.alloc(5 * 1024 * 1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -1193,7 +1193,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlockBlobRange', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(5 * 1024 * 1024);
var blobBuffer = Buffer.alloc(5 * 1024 * 1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -1226,7 +1226,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getPageBlobRange', [], suite.isMocked) + '.test';
var blobBuffer = new Buffer(5 * 1024 * 1024);
var blobBuffer = Buffer.alloc(5 * 1024 * 1024);
blobBuffer.fill(0);
blobBuffer[0] = '1';
@ -1369,7 +1369,7 @@ describe('blob-uploaddownload-tests', function () {
var zeroFileContentMD5;
before(function (done) {
blockBlobContentMD5 = writeFile(blockFileName, fileText);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -1597,7 +1597,7 @@ describe('blob-uploaddownload-tests', function () {
before(function (done) {
blockBlobContentMD5 = writeFile(blockFileName, fileText);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -1692,8 +1692,8 @@ describe('blob-uploaddownload-tests', function () {
storeBlobContentMD5: false,
useTransactionalMD5: false
};
var buffer = new Buffer(15 * 1024 * 1024);
var tempBuffer = new Buffer(10);
var buffer = Buffer.alloc(15 * 1024 * 1024);
var tempBuffer = Buffer.alloc(10);
var uploadLength = buffer.length + tempBuffer.length;
buffer.fill(1);
tempBuffer.fill(2);
@ -1748,8 +1748,8 @@ describe('blob-uploaddownload-tests', function () {
useTransactionalMD5: true
};
var expectedMD5;
var buffer = new Buffer(20 * 1024 * 1024);
var tempBuffer = new Buffer(10);
var buffer = Buffer.alloc(20 * 1024 * 1024);
var tempBuffer = Buffer.alloc(10);
var uploadLength = buffer.length * 2 + tempBuffer.length;
buffer.fill(1);
var internalHash = crypto.createHash('md5');
@ -1791,7 +1791,7 @@ describe('blob-uploaddownload-tests', function () {
parallelOperationThreadCount: 4
};
var expectedMD5;
var buffer = new Buffer(25 * 1024 * 1024);
var buffer = Buffer.alloc(25 * 1024 * 1024);
var uploadLength = buffer.length * 3;
buffer.fill(1);
var internalHash = crypto.createHash('md5');
@ -1835,7 +1835,7 @@ describe('blob-uploaddownload-tests', function () {
pageBlobContentMD5 = writeFile(pageFileName, pageBlobBuffer);
pageBlob2KBuffer.fill(1);
pageBlob2KContentMD5 = writeFile(page2KFileName, pageBlob2KBuffer);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -2115,8 +2115,8 @@ describe('blob-uploaddownload-tests', function () {
storeBlobContentMD5: true,
useTransactionalMD5: true
};
var buffer = new Buffer(15 * 1024 * 1024);
var tempBuffer = new Buffer(512);
var buffer = Buffer.alloc(15 * 1024 * 1024);
var tempBuffer = Buffer.alloc(512);
var uploadLength = buffer.length + tempBuffer.length;
buffer.fill(1);
tempBuffer.fill(2);
@ -2156,7 +2156,7 @@ describe('blob-uploaddownload-tests', function () {
parallelOperationThreadCount : 4
};
var buffer = new Buffer(65 * 1024 * 1024);
var buffer = Buffer.alloc(65 * 1024 * 1024);
buffer.fill(1);
var stream = rfs.createReadStream(pageFileName);
@ -2181,7 +2181,7 @@ describe('blob-uploaddownload-tests', function () {
appendBlobContentMD5 = writeFile(appendFileName, appendBlobBuffer);
appendBlob2KBuffer.fill(1);
appendBlob2KContentMD5 = writeFile(append2KFileName, appendBlob2KBuffer);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -2345,7 +2345,7 @@ describe('blob-uploaddownload-tests', function () {
before(function (done) {
appendBlobContentMD5 = writeFile(appendFileName, fileText);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -2443,8 +2443,8 @@ describe('blob-uploaddownload-tests', function () {
storeBlobContentMD5: true,
useTransactionalMD5: true
};
var buffer = new Buffer(15 * 1024 * 1024);
var tempBuffer = new Buffer(512);
var buffer = Buffer.alloc(15 * 1024 * 1024);
var tempBuffer = Buffer.alloc(512);
var uploadLength = buffer.length + tempBuffer.length;
buffer.fill(1);
tempBuffer.fill(2);
@ -2879,7 +2879,7 @@ describe('blob-uploaddownload-tests', function () {
it('should download a block blob to a local file in chunks', function (done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlockBlobRangeStreamLocal', [], suite.isMocked) + '.test';
var buffer = new Buffer(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var buffer = Buffer.alloc(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var originLimit = blobService.singleBlobPutThresholdInBytes;
buffer.fill(0);
writeFile(fileNameSource, buffer);
@ -2910,7 +2910,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameSource = testutil.generateId('getBlockBlobRangeStreamLocal', [], suite.isMocked) + '.test';
var buffer = new Buffer(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var buffer = Buffer.alloc(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var originLimit = blobService.singleBlobPutThresholdInBytes;
buffer.fill(0);
writeFile(fileNameSource, buffer);
@ -2984,7 +2984,7 @@ describe('blob-uploaddownload-tests', function () {
it('should work with basic stream for block blob', function(done) {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('createWriteStreamToBlockBlob', [], suite.isMocked) + '.blocktest';
var blobBuffer = new Buffer(99);
var blobBuffer = Buffer.alloc(99);
blobBuffer.fill(1);
// Write file so that it can be piped
@ -3006,7 +3006,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('createWriteStreamToPageBlob', [], suite.isMocked) + '.pagetest';
var length = 99;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill('b');
// Write file so that it can be piped
fs.writeFileSync(fileNameTarget, blobBuffer);
@ -3024,7 +3024,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('createWriteStreamToPageBlob', [], suite.isMocked) + '.pagetest';
var length = 2 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill('a');
pageBlobContentMD5 = writeFile(fileNameTarget, blobBuffer);
var readable = rfs.createReadStream(fileNameTarget);
@ -3044,7 +3044,7 @@ describe('blob-uploaddownload-tests', function () {
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suite.isMocked);
var fileNameTarget = testutil.generateId('createWriteStreamToAppendBlob', [], suite.isMocked) + '.appendtest';
var length = 2 * 1024 * 1024;
var blobBuffer = new Buffer(length);
var blobBuffer = Buffer.alloc(length);
blobBuffer.fill('a');
pageBlobContentMD5 = writeFile(fileNameTarget, blobBuffer);
var readable = rfs.createReadStream(fileNameTarget);

Просмотреть файл

@ -129,7 +129,7 @@ describe('FileUploadDownloadScale', function () {
function generateTempFile(fileName, size, callback) {
var blockSize = 4 * 1024 * 1024;
if(!internalBuffer) {
internalBuffer = new Buffer(blockSize);
internalBuffer = Buffer.alloc(blockSize);
}
var md5hash = crypto.createHash('md5');
var fileInfo = {name: fileName, contentMD5: '', size: size};
@ -142,7 +142,7 @@ describe('FileUploadDownloadScale', function () {
content = internalBuffer;
size -= blockSize;
} else {
content = new Buffer(size);
content = Buffer.alloc(size);
size = 0;
}
if (content.length) {

Просмотреть файл

@ -85,7 +85,7 @@ function generateTempFile(fileName, size, hasEmptyBlock, callback) {
var buffer;
if (zero) {
buffer = new Buffer(writeSize);
buffer = Buffer.alloc(writeSize);
buffer.fill(0);
} else {
buffer = crypto.randomBytes(writeSize);
@ -146,7 +146,7 @@ describe('FileUploadDownload', function () {
describe('createWriteStream', function() {
skipMockAndBrowser('existing file', function (done) {
var fileBuffer = new Buffer( 5 * 1024 * 1024 );
var fileBuffer = Buffer.alloc( 5 * 1024 * 1024 );
fileBuffer.fill(1);
// Write file so that it can be piped
@ -169,7 +169,7 @@ describe('FileUploadDownload', function () {
});
skipMockAndBrowser('new file', function (done) {
var fileBuffer = new Buffer( 6 * 1024 * 1024 );
var fileBuffer = Buffer.alloc( 6 * 1024 * 1024 );
fileBuffer.fill(1);
// Write file so that it can be piped
@ -189,7 +189,7 @@ describe('FileUploadDownload', function () {
});
skipMockAndBrowser('store the MD5 on the server', function (done) {
var fileBuffer = new Buffer( 3 * 1024 * 1024 );
var fileBuffer = Buffer.alloc( 3 * 1024 * 1024 );
fileBuffer.fill(1);
// Write file so that it can be piped
@ -232,7 +232,7 @@ describe('FileUploadDownload', function () {
var sourceFileNameTarget = testutil.generateId('getFileSourceFile', [], suite.isMocked) + '.test';
var destinationFileNameTarget = testutil.generateId('getFileDestinationFile', [], suite.isMocked) + '.test';
var fileBuffer = new Buffer( 5 * 1024 );
var fileBuffer = Buffer.alloc( 5 * 1024 );
fileBuffer.fill(1);
fs.writeFileSync(sourceFileNameTarget, fileBuffer);
@ -400,7 +400,7 @@ describe('FileUploadDownload', function () {
describe('clearRange', function() {
skipBrowser('should work', function (done) {
var buffer = new Buffer(512);
var buffer = Buffer.alloc(512);
buffer.fill(0);
buffer[0] = '1';
writeFile(localFileName, buffer);
@ -427,7 +427,7 @@ describe('FileUploadDownload', function () {
});
skipBrowser('multiple ranges', function (done) {
var buffer = new Buffer(1024);
var buffer = Buffer.alloc(1024);
buffer.fill(0);
buffer[0] = '1';
writeFile(localFileName, buffer);
@ -458,7 +458,7 @@ describe('FileUploadDownload', function () {
describe('listRanges', function() {
skipBrowser('should work', function (done) {
var buffer = new Buffer(512);
var buffer = Buffer.alloc(512);
buffer.fill(0);
buffer[0] = '1';
writeFile(localFileName, buffer);
@ -499,7 +499,7 @@ describe('FileUploadDownload', function () {
});
skipBrowser('multiple discrete ranges', function (done) {
var buffer = new Buffer(512);
var buffer = Buffer.alloc(512);
buffer.fill(0);
buffer[0] = '1';
writeFile(localFileName, buffer);
@ -673,7 +673,7 @@ describe('FileUploadDownload', function () {
});
skipBrowser('should download a file to a local file in chunks', function (done) {
var buffer = new Buffer(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var buffer = Buffer.alloc(4 * 1024 * 1024 + 512); // Don't be a multiple of 4MB to cover more scenarios
var originLimit = fileService.singleFileThresholdInBytes;
buffer.fill(0);
writeFile(localFileName, buffer);
@ -901,7 +901,7 @@ describe('FileUploadDownload', function () {
});
it('should work with buffer', function (done) {
var fileText = new Buffer('Hello World');
var fileText = Buffer.from('Hello World');
fileService.createFileFromText(shareName, directoryName, fileName, fileText, function (uploadError, file, uploadResponse) {
assert.equal(uploadError, null);
assert.ok(file);
@ -949,7 +949,7 @@ describe('FileUploadDownload', function () {
var fileContentMD5;
before(function (done) {
fileContentMD5 = writeFile(localFileName, fileText);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -1080,7 +1080,7 @@ describe('FileUploadDownload', function () {
before(function (done) {
fileContentMD5 = writeFile(localFileName, fileText);
var zeroBuffer = new Buffer(0);
var zeroBuffer = Buffer.alloc(0);
zeroFileContentMD5 = writeFile(zeroSizeFileName, zeroBuffer);
done();
});
@ -1174,7 +1174,7 @@ describe('FileUploadDownload', function () {
skipMockAndBrowser('should work with parallelOperationsThreadCount in options', function(done) {
var options = { parallelOperationThreadCount : 4 };
var buffer = new Buffer(65 * 1024 * 1024);
var buffer = Buffer.alloc(65 * 1024 * 1024);
buffer.fill(0);
buffer[0] = '1';
writeFile(localFileName, buffer);
@ -1203,7 +1203,7 @@ describe('FileUploadDownload', function () {
};
skipMockAndBrowser('storeFileContentMD5/useTransactionalMD5 on file', function (done) {
var fileBuffer = new Buffer(5 * 1024 * 1024);
var fileBuffer = Buffer.alloc(5 * 1024 * 1024);
fileBuffer.fill(0);
fileBuffer[0] = '1';
var fileMD5 = writeFile(localFileName, fileBuffer);
@ -1234,7 +1234,7 @@ describe('FileUploadDownload', function () {
});
skipBrowser('storeFileContentMD5/useTransactionalMD5 with streams/ranges', function (done) {
var fileBuffer = new Buffer(5 * 1024 * 1024);
var fileBuffer = Buffer.alloc(5 * 1024 * 1024);
fileBuffer.fill(0);
fileBuffer[0] = '1';
var fileMD5 = writeFile(localFileName, fileBuffer);
@ -1289,7 +1289,7 @@ describe('FileUploadDownload', function () {
});
skipMockAndBrowser('disableContentMD5Validation', function (done) {
var fileBuffer = new Buffer(5 * 1024 * 1024);
var fileBuffer = Buffer.alloc(5 * 1024 * 1024);
fileBuffer.fill(0);
fileBuffer[0] = '1';
var fileMD5 = writeFile(localFileName, fileBuffer);

Просмотреть файл

@ -448,14 +448,14 @@ describe('QueueServiceTests', function() {
assert.equal(createResponse1.statusCode, HttpConstants.HttpResponseCodes.Created);
// Create message
queueService.createMessage(queueName, new Buffer(messageText1), function (createMessageError, createdMessage, createMessageResponse) {
queueService.createMessage(queueName, Buffer.from(messageText1), function (createMessageError, createdMessage, createMessageResponse) {
assert.equal(createMessageError, null);
assert.notEqual(createdMessage, null);
assert.ok(createMessageResponse.isSuccessful);
assert.equal(createMessageResponse.statusCode, HttpConstants.HttpResponseCodes.Created);
// Create another message
queueService.createMessage(queueName, new Buffer(messageText2), function (createMessageError2, createdMessage2, createMessageResponse2) {
queueService.createMessage(queueName, Buffer.from(messageText2), function (createMessageError2, createdMessage2, createMessageResponse2) {
assert.equal(createMessageError, null);
assert.notEqual(createdMessage2, null);
assert.ok(createMessageResponse2.isSuccessful);
@ -639,14 +639,14 @@ describe('QueueServiceTests', function() {
assert.equal(createResponse1.statusCode, HttpConstants.HttpResponseCodes.Created);
// Create message
queueService.createMessage(queueName, new Buffer(messageText1), function (createMessageError, createdMessage, createMessageResponse) {
queueService.createMessage(queueName, Buffer.from(messageText1), function (createMessageError, createdMessage, createMessageResponse) {
assert.equal(createMessageError, null);
assert.notEqual(createdMessage, null);
assert.ok(createMessageResponse.isSuccessful);
assert.equal(createMessageResponse.statusCode, HttpConstants.HttpResponseCodes.Created);
// Create another message
queueService.createMessage(queueName, new Buffer(messageText2), function (createMessageError2, createdMessage2, createMessageResponse2) {
queueService.createMessage(queueName, Buffer.from(messageText2), function (createMessageError2, createdMessage2, createMessageResponse2) {
assert.equal(createMessageError, null);
assert.notEqual(createdMessage2, null);
assert.ok(createMessageResponse2.isSuccessful);

Просмотреть файл

@ -68,7 +68,7 @@ function generateEntities(count) {
RowKey: eg.String('row' + (i + 1).toString()),
StringProperty: eg.String('stringSample'),
BooleanProperty: eg.Boolean(true),
BinaryProperty: eg.Binary(new Buffer('SampleStringInBuffer!')),
BinaryProperty: eg.Binary(Buffer.from('SampleStringInBuffer!')),
Int32Property: eg.Int32(42),
Int64Property: eg.Int64('5432873627392'),
DoubleProperty: eg.Double(4.81516),

Просмотреть файл

@ -50,7 +50,7 @@ var doubleVal = 123.45;
var boolVal = false;
var dateVal = new Date(Date.UTC(2012, 10, 10, 3, 4, 5, 200));
var guidVal = 'debc44d5-04a9-42ea-ab2f-4e2cb49ff833';
var binaryVal = new Buffer(3);
var binaryVal = Buffer.alloc(3);
binaryVal[0] = 0x01;
binaryVal[1] = 0x02;
binaryVal[2] = 50;

Просмотреть файл

@ -75,7 +75,7 @@ var getNewEntityToTest = function () {
RowKey: eg.String('row1'),
StringProperty: eg.String('stringSample'),
BooleanProperty: eg.Boolean(true, 'Edm.Boolean'),
BinaryProperty: eg.Binary(new Buffer('SampleStringInBuffer!')),
BinaryProperty: eg.Binary(Buffer.from('SampleStringInBuffer!')),
Int32Property: eg.Int32(42),
Int64Property: eg.Int64('5432873627392'),
DoubleProperty: eg.Double(4.81516),
@ -316,7 +316,7 @@ function compareProperties (propFromService, prop, expectTypeOnService) {
}
}
if (prop['$'] === 'Edm.Binary' && (!propFromService.hasOwnProperty('$') || propFromService['$'] === 'Edm.String')) {
assert.strictEqual(new Buffer(propFromService['_'], 'base64').toString(), prop['_'].toString());
assert.strictEqual(Buffer.from(propFromService['_'], 'base64').toString(), prop['_'].toString());
} else if (prop['$'] === 'Edm.DateTime' && (!propFromService.hasOwnProperty('$') || propFromService['$'] === 'Edm.String')){
assert.strictEqual((new Date(propFromService['_'])).toString(), prop['_'].toString());
} else if (prop['$'] === 'Edm.Double') {
@ -526,7 +526,7 @@ function entityResolverTest (options, done) {
PartitionKey: eg.String('partition1'),
RowKey: eg.String('row1'),
BooleanProperty: eg.Boolean(true),
BinaryProperty: eg.Binary(new Buffer('SampleStringInBuffer!')),
BinaryProperty: eg.Binary(Buffer.from('SampleStringInBuffer!')),
Int32Property: eg.Int32(42)
};

Просмотреть файл

@ -133,7 +133,7 @@ describe('tableservice-tests', function () {
it('SetDefaultPortProperly', function (done) {
var storageAccount = 'account';
var storageAccountKey = new Buffer('key').toString('base64');
var storageAccountKey = Buffer.from('key').toString('base64');
var service = azure.createTableService(storageAccount, storageAccountKey, 'https://account.table.core.windows.net');
assert.equal(service.host.primaryHost, 'https://account.table.core.windows.net:443/');

2
typings/azure-storage/azure-storage.d.ts поставляемый
Просмотреть файл

@ -5902,7 +5902,7 @@ declare module azurestorage {
* @param {string|buffer}value A 'buffer' containing the value to compare with the property.
* @return {string} A string containing the formatted filter condition.
* @example
* var query = TableQuery.binaryFilter('BinaryField', QueryComparisons.EQUAL, new Buffer('hello'));
* var query = TableQuery.binaryFilter('BinaryField', QueryComparisons.EQUAL, Buffer.from('hello'));
*/
binaryFilter(propertyName: string, operation: string, value: Buffer | string): string;