use size_t in storage sdk (#2320)
* use size_t instead of std::size_t * use size_t for file write length * fix build error * fix build errors * fix build error
This commit is contained in:
parent
f2c0546386
commit
ce30cca1cb
@ -260,7 +260,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
*/
|
||||
Azure::Response<Models::DownloadBlobToResult> DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadBlobToOptions& options = DownloadBlobToOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
*/
|
||||
Azure::Response<Models::UploadBlockBlobFromResult> UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadBlockBlobFromOptions& options = UploadBlockBlobFromOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
|
||||
@ -2726,7 +2726,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
"deleted",
|
||||
};
|
||||
std::string ret;
|
||||
for (std::size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobContainersIncludeFlags); ++i)
|
||||
for (size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobContainersIncludeFlags); ++i)
|
||||
{
|
||||
if ((val & value_list[i]) == value_list[i])
|
||||
{
|
||||
@ -2759,7 +2759,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
"uncommittedblobs",
|
||||
};
|
||||
std::string ret;
|
||||
for (std::size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobsIncludeFlags); ++i)
|
||||
for (size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobsIncludeFlags); ++i)
|
||||
{
|
||||
if ((val & value_list[i]) == value_list[i])
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@ void BlobsGettingStarted()
|
||||
{
|
||||
std::cout << metadata.first << ":" << metadata.second << std::endl;
|
||||
}
|
||||
blobContent.resize(static_cast<std::size_t>(properties.BlobSize));
|
||||
blobContent.resize(static_cast<size_t>(properties.BlobSize));
|
||||
|
||||
blobClient.DownloadTo(reinterpret_cast<uint8_t*>(&blobContent[0]), blobContent.size());
|
||||
|
||||
|
||||
@ -218,7 +218,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
Azure::Response<Models::DownloadBlobToResult> BlobClient::DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadBlobToOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
@ -258,7 +258,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
}
|
||||
firstChunkLength = std::min(firstChunkLength, blobRangeSize);
|
||||
|
||||
if (static_cast<std::size_t>(blobRangeSize) > bufferSize)
|
||||
if (static_cast<size_t>(blobRangeSize) > bufferSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException(
|
||||
"buffer is not big enough, blob range size is " + std::to_string(blobRangeSize));
|
||||
@ -372,15 +372,14 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto bodyStreamToFile = [](Azure::Core::IO::BodyStream& stream,
|
||||
_internal::FileWriter& fileWriter,
|
||||
int64_t offset,
|
||||
int64_t length,
|
||||
size_t length,
|
||||
const Azure::Core::Context& context) {
|
||||
constexpr std::size_t bufferSize = 4 * 1024 * 1024;
|
||||
constexpr size_t bufferSize = 4 * 1024 * 1024;
|
||||
std::vector<uint8_t> buffer(bufferSize);
|
||||
while (length > 0)
|
||||
{
|
||||
int64_t readSize = std::min(static_cast<int64_t>(bufferSize), length);
|
||||
int64_t bytesRead
|
||||
= stream.ReadToCount(buffer.data(), static_cast<size_t>(readSize), context);
|
||||
size_t readSize = std::min(bufferSize, length);
|
||||
size_t bytesRead = stream.ReadToCount(buffer.data(), readSize, context);
|
||||
if (bytesRead != readSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
@ -391,7 +390,12 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
}
|
||||
};
|
||||
|
||||
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
|
||||
bodyStreamToFile(
|
||||
*(firstChunk.Value.BodyStream),
|
||||
fileWriter,
|
||||
0,
|
||||
static_cast<size_t>(firstChunkLength),
|
||||
context);
|
||||
firstChunk.Value.BodyStream.reset();
|
||||
|
||||
auto returnTypeConverter = [](Azure::Response<Models::DownloadBlobResult>& response) {
|
||||
@ -422,7 +426,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
*(chunk.Value.BodyStream),
|
||||
fileWriter,
|
||||
offset - firstChunkOffset,
|
||||
chunkOptions.Range.Value().Length.Value(),
|
||||
static_cast<size_t>(chunkOptions.Range.Value().Length.Value()),
|
||||
context);
|
||||
|
||||
if (chunkId == numChunks - 1)
|
||||
|
||||
@ -118,7 +118,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
Azure::Response<Models::UploadBlockBlobFromResult> BlockBlobClient::UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadBlockBlobFromOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
@ -127,7 +127,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
constexpr int64_t MaxBlockNumber = 50000;
|
||||
constexpr int64_t BlockGrainSize = 1 * 1024 * 1024;
|
||||
|
||||
if (bufferSize <= static_cast<std::size_t>(options.TransferOptions.SingleUploadThreshold))
|
||||
if (bufferSize <= static_cast<size_t>(options.TransferOptions.SingleUploadThreshold))
|
||||
{
|
||||
Azure::Core::IO::MemoryBodyStream contentStream(buffer, bufferSize);
|
||||
UploadBlockBlobOptions uploadBlockBlobOptions;
|
||||
@ -155,7 +155,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
std::vector<std::string> blockIds;
|
||||
auto getBlockId = [](int64_t id) {
|
||||
constexpr std::size_t BlockIdLength = 64;
|
||||
constexpr size_t BlockIdLength = 64;
|
||||
std::string blockId = std::to_string(id);
|
||||
blockId = std::string(BlockIdLength - blockId.length(), '0') + blockId;
|
||||
return Azure::Core::Convert::Base64Encode(
|
||||
@ -170,14 +170,14 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto blockInfo = StageBlock(getBlockId(chunkId), contentStream, chunkOptions, context);
|
||||
if (chunkId == numChunks - 1)
|
||||
{
|
||||
blockIds.resize(static_cast<std::size_t>(numChunks));
|
||||
blockIds.resize(static_cast<size_t>(numChunks));
|
||||
}
|
||||
};
|
||||
|
||||
_internal::ConcurrentTransfer(
|
||||
0, bufferSize, chunkSize, options.TransferOptions.Concurrency, uploadBlockFunc);
|
||||
|
||||
for (std::size_t i = 0; i < blockIds.size(); ++i)
|
||||
for (size_t i = 0; i < blockIds.size(); ++i)
|
||||
{
|
||||
blockIds[i] = getBlockId(static_cast<int64_t>(i));
|
||||
}
|
||||
@ -223,7 +223,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
std::vector<std::string> blockIds;
|
||||
auto getBlockId = [](int64_t id) {
|
||||
constexpr std::size_t BlockIdLength = 64;
|
||||
constexpr size_t BlockIdLength = 64;
|
||||
std::string blockId = std::to_string(id);
|
||||
blockId = std::string(BlockIdLength - blockId.length(), '0') + blockId;
|
||||
return Azure::Core::Convert::Base64Encode(
|
||||
@ -239,7 +239,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto blockInfo = StageBlock(getBlockId(chunkId), contentStream, chunkOptions, context);
|
||||
if (chunkId == numChunks - 1)
|
||||
{
|
||||
blockIds.resize(static_cast<std::size_t>(numChunks));
|
||||
blockIds.resize(static_cast<size_t>(numChunks));
|
||||
}
|
||||
};
|
||||
|
||||
@ -266,7 +266,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
options.TransferOptions.Concurrency,
|
||||
uploadBlockFunc);
|
||||
|
||||
for (std::size_t i = 0; i < blockIds.size(); ++i)
|
||||
for (size_t i = 0; i < blockIds.size(); ++i)
|
||||
{
|
||||
blockIds[i] = getBlockId(static_cast<int64_t>(i));
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
StandardStorageConnectionString(), m_containerName, m_blobName);
|
||||
m_blockBlobClient
|
||||
= std::make_shared<Azure::Storage::Blobs::BlockBlobClient>(std::move(blockBlobClient));
|
||||
m_blobContent.resize(static_cast<std::size_t>(8_MB));
|
||||
m_blobContent.resize(static_cast<size_t>(8_MB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&m_blobContent[0]), m_blobContent.size());
|
||||
m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"key2", "Value2"}};
|
||||
m_blobUploadOptions.HttpHeaders.ContentType = "application/x-binary";
|
||||
@ -99,9 +99,9 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(
|
||||
ReadBodyStream(res.Value.BodyStream),
|
||||
std::vector<uint8_t>(
|
||||
m_blobContent.begin() + static_cast<std::size_t>(options.Range.Value().Offset),
|
||||
m_blobContent.begin() + static_cast<size_t>(options.Range.Value().Offset),
|
||||
m_blobContent.begin()
|
||||
+ static_cast<std::size_t>(
|
||||
+ static_cast<size_t>(
|
||||
options.Range.Value().Offset + options.Range.Value().Length.Value())));
|
||||
EXPECT_EQ(res.Value.ContentRange.Offset, options.Range.Value().Offset);
|
||||
EXPECT_EQ(res.Value.ContentRange.Length.Value(), options.Range.Value().Length.Value());
|
||||
@ -459,7 +459,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
expectedData.clear();
|
||||
}
|
||||
}
|
||||
downloadBuffer.resize(static_cast<std::size_t>(downloadSize), '\x00');
|
||||
downloadBuffer.resize(static_cast<size_t>(downloadSize), '\x00');
|
||||
Blobs::DownloadBlobToOptions options;
|
||||
options.TransferOptions.Concurrency = concurrency;
|
||||
if (offset.HasValue() || length.HasValue())
|
||||
@ -483,7 +483,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(res.Value.BlobSize, blobSize);
|
||||
EXPECT_EQ(res.Value.ContentRange.Length.Value(), actualDownloadSize);
|
||||
EXPECT_EQ(res.Value.ContentRange.Offset, offset.HasValue() ? offset.Value() : 0);
|
||||
downloadBuffer.resize(static_cast<std::size_t>(res.Value.ContentRange.Length.Value()));
|
||||
downloadBuffer.resize(static_cast<size_t>(res.Value.ContentRange.Length.Value()));
|
||||
EXPECT_EQ(downloadBuffer, expectedData);
|
||||
}
|
||||
else
|
||||
@ -626,11 +626,11 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
for (int64_t length : {1ULL, 2ULL, 4_KB, 5_KB, 8_KB, 11_KB, 20_KB})
|
||||
{
|
||||
std::vector<uint8_t> downloadBuffer;
|
||||
downloadBuffer.resize(static_cast<std::size_t>(length - 1));
|
||||
downloadBuffer.resize(static_cast<size_t>(length - 1));
|
||||
options.Range.Value().Length = length;
|
||||
EXPECT_THROW(
|
||||
m_blockBlobClient->DownloadTo(
|
||||
downloadBuffer.data(), static_cast<std::size_t>(length - 1), options),
|
||||
downloadBuffer.data(), static_cast<size_t>(length - 1), options),
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
@ -726,7 +726,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_TRUE(ReadFile(tempFilename).empty());
|
||||
DeleteFile(tempFilename);
|
||||
|
||||
res = blockBlobClient.DownloadTo(emptyContent.data(), static_cast<std::size_t>(8_MB));
|
||||
res = blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB));
|
||||
EXPECT_EQ(res.Value.BlobSize, 0);
|
||||
EXPECT_EQ(res.Value.ContentRange.Length.Value(), 0);
|
||||
EXPECT_TRUE(res.Value.Details.ETag.HasValue());
|
||||
@ -752,8 +752,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
options.TransferOptions.ChunkSize = 10;
|
||||
options.TransferOptions.Concurrency = c;
|
||||
|
||||
res = blockBlobClient.DownloadTo(
|
||||
emptyContent.data(), static_cast<std::size_t>(8_MB), options);
|
||||
res = blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB), options);
|
||||
EXPECT_EQ(res.Value.BlobSize, 0);
|
||||
EXPECT_EQ(res.Value.ContentRange.Length.Value(), 0);
|
||||
EXPECT_TRUE(res.Value.Details.ETag.HasValue());
|
||||
@ -775,27 +774,27 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
options.Range = Core::Http::HttpRange();
|
||||
options.Range.Value().Offset = 0;
|
||||
EXPECT_THROW(
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<std::size_t>(8_MB), options),
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB), options),
|
||||
StorageException);
|
||||
EXPECT_THROW(blockBlobClient.DownloadTo(tempFilename, options), StorageException);
|
||||
|
||||
options.Range.Value().Offset = 1;
|
||||
EXPECT_THROW(
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<std::size_t>(8_MB), options),
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB), options),
|
||||
StorageException);
|
||||
EXPECT_THROW(blockBlobClient.DownloadTo(tempFilename, options), StorageException);
|
||||
|
||||
options.Range.Value().Offset = 0;
|
||||
options.Range.Value().Length = 1;
|
||||
EXPECT_THROW(
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<std::size_t>(8_MB), options),
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB), options),
|
||||
StorageException);
|
||||
EXPECT_THROW(blockBlobClient.DownloadTo(tempFilename, options), StorageException);
|
||||
|
||||
options.Range.Value().Offset = 100;
|
||||
options.Range.Value().Length = 100;
|
||||
EXPECT_THROW(
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<std::size_t>(8_MB), options),
|
||||
blockBlobClient.DownloadTo(emptyContent.data(), static_cast<size_t>(8_MB), options),
|
||||
StorageException);
|
||||
EXPECT_THROW(blockBlobClient.DownloadTo(tempFilename, options), StorageException);
|
||||
DeleteFile(tempFilename);
|
||||
@ -804,7 +803,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
TEST_F(BlockBlobClientTest, ConcurrentUpload)
|
||||
{
|
||||
std::vector<uint8_t> blobContent = RandomBuffer(static_cast<std::size_t>(8_MB));
|
||||
std::vector<uint8_t> blobContent = RandomBuffer(static_cast<size_t>(8_MB));
|
||||
|
||||
auto testUploadFromBuffer = [&](int concurrency, int64_t blobSize) {
|
||||
auto blockBlobClient = m_blobContainerClient->GetBlockBlobClient(RandomString());
|
||||
@ -816,8 +815,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
options.HttpHeaders.ContentHash.Value.clear();
|
||||
options.Metadata = m_blobUploadOptions.Metadata;
|
||||
options.AccessTier = m_blobUploadOptions.AccessTier;
|
||||
auto res = blockBlobClient.UploadFrom(
|
||||
blobContent.data(), static_cast<std::size_t>(blobSize), options);
|
||||
auto res
|
||||
= blockBlobClient.UploadFrom(blobContent.data(), static_cast<size_t>(blobSize), options);
|
||||
EXPECT_TRUE(res.Value.ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(res.Value.LastModified));
|
||||
auto properties = blockBlobClient.GetProperties().Value;
|
||||
@ -828,12 +827,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(properties.AccessTier.Value(), options.AccessTier.Value());
|
||||
EXPECT_EQ(properties.ETag, res.Value.ETag);
|
||||
EXPECT_EQ(properties.LastModified, res.Value.LastModified);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(blobSize), '\x00');
|
||||
blockBlobClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(blobSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(blobSize), '\x00');
|
||||
blockBlobClient.DownloadTo(downloadContent.data(), static_cast<size_t>(blobSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
blobContent.begin(), blobContent.begin() + static_cast<std::size_t>(blobSize)));
|
||||
blobContent.begin(), blobContent.begin() + static_cast<size_t>(blobSize)));
|
||||
};
|
||||
|
||||
auto testUploadFromFile = [&](int concurrency, int64_t blobSize) {
|
||||
@ -850,7 +849,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::string tempFilename = RandomString();
|
||||
{
|
||||
Azure::Storage::_internal::FileWriter fileWriter(tempFilename);
|
||||
fileWriter.Write(blobContent.data(), blobSize, 0);
|
||||
fileWriter.Write(blobContent.data(), static_cast<size_t>(blobSize), 0);
|
||||
}
|
||||
auto res = blockBlobClient.UploadFrom(tempFilename, options);
|
||||
EXPECT_TRUE(res.Value.ETag.HasValue());
|
||||
@ -863,12 +862,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(properties.AccessTier.Value(), options.AccessTier.Value());
|
||||
EXPECT_EQ(properties.ETag, res.Value.ETag);
|
||||
EXPECT_EQ(properties.LastModified, res.Value.LastModified);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(blobSize), '\x00');
|
||||
blockBlobClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(blobSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(blobSize), '\x00');
|
||||
blockBlobClient.DownloadTo(downloadContent.data(), static_cast<size_t>(blobSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
blobContent.begin(), blobContent.begin() + static_cast<std::size_t>(blobSize)));
|
||||
blobContent.begin(), blobContent.begin() + static_cast<size_t>(blobSize)));
|
||||
DeleteFile(tempFilename);
|
||||
};
|
||||
|
||||
@ -878,7 +877,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
for (int64_t l :
|
||||
{0ULL, 1ULL, 2ULL, 2_KB, 4_KB, 999_KB, 1_MB, 2_MB - 1, 3_MB, 5_MB, 8_MB - 1234, 8_MB})
|
||||
{
|
||||
ASSERT_GE(blobContent.size(), static_cast<std::size_t>(l));
|
||||
ASSERT_GE(blobContent.size(), static_cast<size_t>(l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromBuffer, c, l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromFile, c, l));
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
StandardStorageConnectionString(), m_containerName, m_blobName);
|
||||
m_pageBlobClient
|
||||
= std::make_shared<Azure::Storage::Blobs::PageBlobClient>(std::move(pageBlobClient));
|
||||
m_blobContent.resize(static_cast<std::size_t>(1_KB));
|
||||
m_blobContent.resize(static_cast<size_t>(1_KB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&m_blobContent[0]), m_blobContent.size());
|
||||
m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"key2", "Value2"}};
|
||||
m_blobUploadOptions.HttpHeaders.ContentType = "application/x-binary";
|
||||
@ -78,7 +78,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
TEST_F(PageBlobClientTest, UploadClear)
|
||||
{
|
||||
std::vector<uint8_t> blobContent;
|
||||
blobContent.resize(static_cast<std::size_t>(4_KB));
|
||||
blobContent.resize(static_cast<size_t>(4_KB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&blobContent[0]), blobContent.size());
|
||||
|
||||
auto pageBlobClient = Azure::Storage::Blobs::PageBlobClient::CreateFromConnectionString(
|
||||
@ -87,13 +87,13 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto pageContent = Azure::Core::IO::MemoryBodyStream(blobContent.data(), blobContent.size());
|
||||
pageBlobClient.UploadPages(2_KB, pageContent);
|
||||
// |_|_|x|x| |x|x|_|_|
|
||||
blobContent.insert(blobContent.begin(), static_cast<std::size_t>(2_KB), '\x00');
|
||||
blobContent.resize(static_cast<std::size_t>(8_KB), '\x00');
|
||||
blobContent.insert(blobContent.begin(), static_cast<size_t>(2_KB), '\x00');
|
||||
blobContent.resize(static_cast<size_t>(8_KB), '\x00');
|
||||
pageBlobClient.ClearPages({2_KB, 1_KB});
|
||||
// |_|_|_|x| |x|x|_|_|
|
||||
std::fill(
|
||||
blobContent.begin() + static_cast<std::size_t>(2_KB),
|
||||
blobContent.begin() + static_cast<std::size_t>(2_KB + 1_KB),
|
||||
blobContent.begin() + static_cast<size_t>(2_KB),
|
||||
blobContent.begin() + static_cast<size_t>(2_KB + 1_KB),
|
||||
'\x00');
|
||||
|
||||
auto downloadContent = pageBlobClient.Download();
|
||||
@ -127,7 +127,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
auto snapshot = pageBlobClient.CreateSnapshot().Value.Snapshot;
|
||||
// |_|_|_|x| |x|x|_|_| This is what's in snapshot
|
||||
blobContent.resize(static_cast<std::size_t>(1_KB));
|
||||
blobContent.resize(static_cast<size_t>(1_KB));
|
||||
auto pageClient = Azure::Core::IO::MemoryBodyStream(blobContent.data(), blobContent.size());
|
||||
pageBlobClient.UploadPages(0, pageClient);
|
||||
pageBlobClient.ClearPages({3_KB, 1_KB});
|
||||
@ -254,7 +254,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
TEST_F(PageBlobClientTest, ContentMd5)
|
||||
{
|
||||
std::vector<uint8_t> blobContent;
|
||||
blobContent.resize(static_cast<std::size_t>(4_KB));
|
||||
blobContent.resize(static_cast<size_t>(4_KB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&blobContent[0]), blobContent.size());
|
||||
|
||||
auto pageBlobClient = Azure::Storage::Blobs::PageBlobClient::CreateFromConnectionString(
|
||||
@ -282,7 +282,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
TEST_F(PageBlobClientTest, ContentCrc64)
|
||||
{
|
||||
std::vector<uint8_t> blobContent;
|
||||
blobContent.resize(static_cast<std::size_t>(4_KB));
|
||||
blobContent.resize(static_cast<size_t>(4_KB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&blobContent[0]), blobContent.size());
|
||||
|
||||
auto pageBlobClient = Azure::Storage::Blobs::PageBlobClient::CreateFromConnectionString(
|
||||
|
||||
@ -36,7 +36,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
break;
|
||||
}
|
||||
int64_t chunkOffset = offset + chunkSize * chunkId;
|
||||
int64_t chunkLength = (std::min)(length - chunkSize * chunkId, chunkSize);
|
||||
int64_t chunkLength = std::min(length - chunkSize * chunkId, chunkSize);
|
||||
try
|
||||
{
|
||||
transferFunc(chunkOffset, chunkLength, chunkId, numChunks);
|
||||
|
||||
@ -32,8 +32,8 @@ namespace Azure { namespace Storage {
|
||||
uint64_t m_context = 0ULL;
|
||||
uint64_t m_length = 0ULL;
|
||||
|
||||
void OnAppend(const uint8_t* data, std::size_t length) override;
|
||||
std::vector<uint8_t> OnFinal(const uint8_t* data, std::size_t length) override;
|
||||
void OnAppend(const uint8_t* data, size_t length) override;
|
||||
std::vector<uint8_t> OnFinal(const uint8_t* data, size_t length) override;
|
||||
};
|
||||
|
||||
namespace _internal {
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
FileHandle GetHandle() const { return m_handle; }
|
||||
|
||||
void Write(const uint8_t* buffer, int64_t length, int64_t offset);
|
||||
void Write(const uint8_t* buffer, size_t length, int64_t offset);
|
||||
|
||||
private:
|
||||
FileHandle m_handle;
|
||||
|
||||
@ -31,7 +31,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
class XmlReader final {
|
||||
public:
|
||||
explicit XmlReader(const char* data, std::size_t length);
|
||||
explicit XmlReader(const char* data, size_t length);
|
||||
~XmlReader();
|
||||
|
||||
XmlNode Read();
|
||||
|
||||
@ -91,8 +91,8 @@ namespace Azure { namespace Storage {
|
||||
struct AlgorithmProviderInstance final
|
||||
{
|
||||
BCRYPT_ALG_HANDLE Handle;
|
||||
std::size_t ContextSize;
|
||||
std::size_t HashLength;
|
||||
size_t ContextSize;
|
||||
size_t HashLength;
|
||||
|
||||
AlgorithmProviderInstance(AlgorithmType type)
|
||||
{
|
||||
@ -910,7 +910,7 @@ namespace Azure { namespace Storage {
|
||||
return vr[0] ^ vr[1];
|
||||
}
|
||||
|
||||
void Crc64Hash::OnAppend(const uint8_t* data, std::size_t length)
|
||||
void Crc64Hash::OnAppend(const uint8_t* data, size_t length)
|
||||
{
|
||||
m_length += length;
|
||||
|
||||
@ -1087,12 +1087,12 @@ namespace Azure { namespace Storage {
|
||||
m_context ^= other.m_context;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Crc64Hash::OnFinal(const uint8_t* data, std::size_t length)
|
||||
std::vector<uint8_t> Crc64Hash::OnFinal(const uint8_t* data, size_t length)
|
||||
{
|
||||
OnAppend(data, length);
|
||||
std::vector<uint8_t> binary;
|
||||
binary.resize(sizeof(m_context));
|
||||
for (std::size_t i = 0; i < sizeof(m_context); ++i)
|
||||
for (size_t i = 0; i < sizeof(m_context); ++i)
|
||||
{
|
||||
binary[i] = (m_context >> (8 * i)) & 0xff;
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
FileWriter::~FileWriter() { CloseHandle(static_cast<HANDLE>(m_handle)); }
|
||||
|
||||
void FileWriter::Write(const uint8_t* buffer, int64_t length, int64_t offset)
|
||||
void FileWriter::Write(const uint8_t* buffer, size_t length, int64_t offset)
|
||||
{
|
||||
if (length > std::numeric_limits<DWORD>::max())
|
||||
{
|
||||
@ -155,16 +155,14 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
FileWriter::~FileWriter() { close(m_handle); }
|
||||
|
||||
void FileWriter::Write(const uint8_t* buffer, int64_t length, int64_t offset)
|
||||
void FileWriter::Write(const uint8_t* buffer, size_t length, int64_t offset)
|
||||
{
|
||||
if (static_cast<uint64_t>(length) > std::numeric_limits<size_t>::max()
|
||||
|| offset > static_cast<int64_t>(std::numeric_limits<off_t>::max()))
|
||||
if (offset > static_cast<int64_t>(std::numeric_limits<off_t>::max()))
|
||||
{
|
||||
throw std::runtime_error("failed to write file");
|
||||
}
|
||||
ssize_t bytesWritten
|
||||
= pwrite(m_handle, buffer, static_cast<size_t>(length), static_cast<off_t>(offset));
|
||||
if (bytesWritten != length)
|
||||
ssize_t bytesWritten = pwrite(m_handle, buffer, length, static_cast<off_t>(offset));
|
||||
if (bytesWritten < 0 || static_cast<size_t>(bytesWritten) != length)
|
||||
{
|
||||
throw std::runtime_error("failed to write file");
|
||||
}
|
||||
|
||||
@ -19,11 +19,11 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|
||||
static void XmlGlobalInitialize() { static XmlGlobalInitializer globalInitializer; }
|
||||
|
||||
XmlReader::XmlReader(const char* data, std::size_t length)
|
||||
XmlReader::XmlReader(const char* data, size_t length)
|
||||
{
|
||||
XmlGlobalInitialize();
|
||||
|
||||
if (length > static_cast<std::size_t>(std::numeric_limits<int>::max()))
|
||||
if (length > static_cast<size_t>(std::numeric_limits<int>::max()))
|
||||
{
|
||||
throw std::runtime_error("xml data too big");
|
||||
}
|
||||
|
||||
@ -53,15 +53,15 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(Azure::Core::Convert::Base64Encode(ComputeHash("")), "AAAAAAAAAAA=");
|
||||
EXPECT_EQ(Azure::Core::Convert::Base64Encode(ComputeHash("Hello Azure!")), "DtjZpL9/o8c=");
|
||||
|
||||
auto data = RandomBuffer(static_cast<std::size_t>(16_MB));
|
||||
auto data = RandomBuffer(static_cast<size_t>(16_MB));
|
||||
{
|
||||
Crc64Hash crc64Single;
|
||||
Crc64Hash crc64Streaming;
|
||||
|
||||
std::size_t length = 0;
|
||||
size_t length = 0;
|
||||
while (length < data.size())
|
||||
{
|
||||
std::size_t s = static_cast<std::size_t>(RandomInt(0, 4_MB));
|
||||
size_t s = static_cast<size_t>(RandomInt(0, 4_MB));
|
||||
s = std::min(s, data.size() - length);
|
||||
crc64Streaming.Append(&data[length], s);
|
||||
crc64Streaming.Append(&data[length], 0);
|
||||
@ -80,7 +80,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
Crc64Hash instance2;
|
||||
for (auto i = RandomInt(0, 5); i > 0; --i)
|
||||
{
|
||||
std::size_t s = static_cast<std::size_t>(RandomInt(0, 512_KB));
|
||||
size_t s = static_cast<size_t>(RandomInt(0, 512_KB));
|
||||
std::string data2;
|
||||
data2.resize(s);
|
||||
RandomBuffer(&data2[0], s);
|
||||
@ -103,7 +103,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
std::size_t s = static_cast<std::size_t>(RandomInt(0, 512_KB));
|
||||
size_t s = static_cast<size_t>(RandomInt(0, 512_KB));
|
||||
std::string data2;
|
||||
data2.resize(s);
|
||||
RandomBuffer(&data2[0], s);
|
||||
|
||||
@ -187,7 +187,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
static char RandomChar()
|
||||
{
|
||||
const char charset[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::uniform_int_distribution<std::size_t> distribution(0, sizeof(charset) - 2);
|
||||
std::uniform_int_distribution<size_t> distribution(0, sizeof(charset) - 2);
|
||||
return charset[distribution(random_generator)];
|
||||
}
|
||||
|
||||
@ -216,12 +216,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
return result;
|
||||
}
|
||||
|
||||
void RandomBuffer(char* buffer, std::size_t length)
|
||||
void RandomBuffer(char* buffer, size_t length)
|
||||
{
|
||||
char* start_addr = buffer;
|
||||
char* end_addr = buffer + length;
|
||||
|
||||
const std::size_t rand_int_size = sizeof(uint64_t);
|
||||
const size_t rand_int_size = sizeof(uint64_t);
|
||||
|
||||
while (uintptr_t(start_addr) % rand_int_size != 0 && start_addr < end_addr)
|
||||
{
|
||||
@ -250,9 +250,9 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
}
|
||||
fseek(fin, 0, SEEK_END);
|
||||
int64_t fileSize = ftell(fin);
|
||||
std::vector<uint8_t> fileContent(static_cast<std::size_t>(fileSize));
|
||||
std::vector<uint8_t> fileContent(static_cast<size_t>(fileSize));
|
||||
fseek(fin, 0, SEEK_SET);
|
||||
std::size_t elementsRead = fread(fileContent.data(), static_cast<size_t>(fileSize), 1, fin);
|
||||
size_t elementsRead = fread(fileContent.data(), static_cast<size_t>(fileSize), 1, fin);
|
||||
if (elementsRead != 1 && fileSize != 0)
|
||||
{
|
||||
throw std::runtime_error("failed to read file");
|
||||
@ -263,7 +263,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
void DeleteFile(const std::string& filename) { std::remove(filename.data()); }
|
||||
|
||||
std::vector<uint8_t> RandomBuffer(std::size_t length)
|
||||
std::vector<uint8_t> RandomBuffer(size_t length)
|
||||
{
|
||||
std::vector<uint8_t> result(length);
|
||||
char* dataPtr = reinterpret_cast<char*>(&result[0]);
|
||||
|
||||
@ -74,12 +74,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
Storage::Metadata RandomMetadata(size_t size = 5);
|
||||
|
||||
void RandomBuffer(char* buffer, std::size_t length);
|
||||
inline void RandomBuffer(uint8_t* buffer, std::size_t length)
|
||||
void RandomBuffer(char* buffer, size_t length);
|
||||
inline void RandomBuffer(uint8_t* buffer, size_t length)
|
||||
{
|
||||
RandomBuffer(reinterpret_cast<char*>(buffer), length);
|
||||
}
|
||||
std::vector<uint8_t> RandomBuffer(std::size_t length);
|
||||
std::vector<uint8_t> RandomBuffer(size_t length);
|
||||
|
||||
inline std::vector<uint8_t> ReadBodyStream(std::unique_ptr<Azure::Core::IO::BodyStream>& stream)
|
||||
{
|
||||
|
||||
@ -200,7 +200,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
*/
|
||||
Azure::Response<Models::UploadFileFromResult> UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadFileFromOptions& options = UploadFileFromOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
@ -233,7 +233,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
*/
|
||||
Azure::Response<Models::DownloadFileToResult> DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadFileToOptions& options = DownloadFileToOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
|
||||
@ -271,7 +271,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
|
||||
Azure::Response<Models::UploadFileFromResult> DataLakeFileClient::UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadFileFromOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
@ -287,7 +287,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
|
||||
Azure::Response<Models::DownloadFileToResult> DataLakeFileClient::DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadFileToOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
|
||||
@ -371,7 +371,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
TEST_F(DataLakeFileClientTest, ConcurrentUploadDownload)
|
||||
{
|
||||
std::vector<uint8_t> fileContent = RandomBuffer(static_cast<std::size_t>(8_MB));
|
||||
std::vector<uint8_t> fileContent = RandomBuffer(static_cast<size_t>(8_MB));
|
||||
|
||||
auto testUploadFromBuffer = [&](int concurrency, int64_t fileSize) {
|
||||
auto fileClient = m_fileSystemClient->GetFileClient(RandomString());
|
||||
@ -381,8 +381,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
options.TransferOptions.Concurrency = concurrency;
|
||||
options.HttpHeaders = GetInterestingHttpHeaders();
|
||||
options.Metadata = RandomMetadata();
|
||||
auto res
|
||||
= fileClient.UploadFrom(fileContent.data(), static_cast<std::size_t>(fileSize), options);
|
||||
auto res = fileClient.UploadFrom(fileContent.data(), static_cast<size_t>(fileSize), options);
|
||||
auto lastModified = fileClient.GetProperties().Value.LastModified;
|
||||
EXPECT_TRUE(res.Value.ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(res.Value.LastModified));
|
||||
@ -394,12 +393,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(properties.ETag, res.Value.ETag);
|
||||
EXPECT_TRUE(IsValidTime(res.Value.LastModified));
|
||||
EXPECT_EQ(properties.LastModified, res.Value.LastModified);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
fileContent.begin(), fileContent.begin() + static_cast<std::size_t>(fileSize)));
|
||||
fileContent.begin(), fileContent.begin() + static_cast<size_t>(fileSize)));
|
||||
};
|
||||
|
||||
auto testUploadFromFile = [&](int concurrency, int64_t fileSize) {
|
||||
@ -414,7 +413,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::string tempFilename = RandomString();
|
||||
{
|
||||
Azure::Storage::_internal::FileWriter fileWriter(tempFilename);
|
||||
fileWriter.Write(fileContent.data(), fileSize, 0);
|
||||
fileWriter.Write(fileContent.data(), static_cast<size_t>(fileSize), 0);
|
||||
}
|
||||
auto res = fileClient.UploadFrom(tempFilename, options);
|
||||
auto lastModified = fileClient.GetProperties().Value.LastModified;
|
||||
@ -427,12 +426,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_EQ(properties.Metadata, options.Metadata);
|
||||
EXPECT_EQ(properties.ETag, res.Value.ETag);
|
||||
EXPECT_EQ(properties.LastModified, res.Value.LastModified);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
fileContent.begin(), fileContent.begin() + static_cast<std::size_t>(fileSize)));
|
||||
fileContent.begin(), fileContent.begin() + static_cast<size_t>(fileSize)));
|
||||
std::string tempFileDestinationName = RandomString();
|
||||
fileClient.DownloadTo(tempFileDestinationName);
|
||||
Azure::Storage::_internal::FileReader fileReader(tempFileDestinationName);
|
||||
@ -448,7 +447,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
for (int64_t l :
|
||||
{0ULL, 1ULL, 2ULL, 2_KB, 4_KB, 999_KB, 1_MB, 2_MB - 1, 3_MB, 5_MB, 8_MB - 1234, 8_MB})
|
||||
{
|
||||
ASSERT_GE(fileContent.size(), static_cast<std::size_t>(l));
|
||||
ASSERT_GE(fileContent.size(), static_cast<size_t>(l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromBuffer, c, l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromFile, c, l));
|
||||
}
|
||||
@ -491,7 +490,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
// Create from Anonymous credential.
|
||||
std::vector<uint8_t> blobContent;
|
||||
blobContent.resize(static_cast<std::size_t>(1_MB));
|
||||
blobContent.resize(static_cast<size_t>(1_MB));
|
||||
RandomBuffer(reinterpret_cast<char*>(&blobContent[0]), blobContent.size());
|
||||
auto objectName = RandomString(10);
|
||||
auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
|
||||
|
||||
@ -1473,7 +1473,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
"deleted",
|
||||
};
|
||||
std::string result;
|
||||
for (std::size_t i = 0; i < sizeof(value_list) / sizeof(ListSharesIncludeFlags); ++i)
|
||||
for (size_t i = 0; i < sizeof(value_list) / sizeof(ListSharesIncludeFlags); ++i)
|
||||
{
|
||||
if ((val & value_list[i]) == value_list[i])
|
||||
{
|
||||
|
||||
@ -135,7 +135,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
*/
|
||||
Azure::Response<Models::DownloadFileToResult> DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadFileToOptions& options = DownloadFileToOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
@ -167,7 +167,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
*/
|
||||
Azure::Response<Models::UploadFileFromResult> UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadFileFromOptions& options = UploadFileFromOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ void FileShareGettingStarted()
|
||||
{
|
||||
std::cout << metadata.first << ":" << metadata.second << std::endl;
|
||||
}
|
||||
fileContent.resize(static_cast<std::size_t>(properties.FileSize));
|
||||
fileContent.resize(static_cast<size_t>(properties.FileSize));
|
||||
|
||||
fileClient.DownloadTo(reinterpret_cast<uint8_t*>(&fileContent[0]), fileContent.size());
|
||||
|
||||
|
||||
@ -646,7 +646,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
|
||||
Azure::Response<Models::DownloadFileToResult> ShareFileClient::DownloadTo(
|
||||
uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const DownloadFileToOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
@ -688,7 +688,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
}
|
||||
firstChunkLength = std::min(firstChunkLength, fileRangeSize);
|
||||
|
||||
if (static_cast<std::size_t>(fileRangeSize) > bufferSize)
|
||||
if (static_cast<size_t>(fileRangeSize) > bufferSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException(
|
||||
"buffer is not big enough, file range size is " + std::to_string(fileRangeSize));
|
||||
@ -796,15 +796,14 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
auto bodyStreamToFile = [](Azure::Core::IO::BodyStream& stream,
|
||||
_internal::FileWriter& fileWriter,
|
||||
int64_t offset,
|
||||
int64_t length,
|
||||
size_t length,
|
||||
const Azure::Core::Context& context) {
|
||||
constexpr std::size_t bufferSize = 4 * 1024 * 1024;
|
||||
constexpr size_t bufferSize = 4 * 1024 * 1024;
|
||||
std::vector<uint8_t> buffer(bufferSize);
|
||||
while (length > 0)
|
||||
{
|
||||
int64_t readSize = std::min(static_cast<int64_t>(bufferSize), length);
|
||||
int64_t bytesRead
|
||||
= stream.ReadToCount(buffer.data(), static_cast<size_t>(readSize), context);
|
||||
size_t readSize = std::min(bufferSize, length);
|
||||
size_t bytesRead = stream.ReadToCount(buffer.data(), readSize, context);
|
||||
if (bytesRead != readSize)
|
||||
{
|
||||
throw Azure::Core::RequestFailedException("error when reading body stream");
|
||||
@ -815,7 +814,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
}
|
||||
};
|
||||
|
||||
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
|
||||
bodyStreamToFile(
|
||||
*(firstChunk.Value.BodyStream),
|
||||
fileWriter,
|
||||
0,
|
||||
static_cast<size_t>(firstChunkLength),
|
||||
context);
|
||||
firstChunk.Value.BodyStream.reset();
|
||||
|
||||
auto returnTypeConverter = [](Azure::Response<Models::DownloadFileResult>& response) {
|
||||
@ -840,7 +844,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
*(chunk.Value.BodyStream),
|
||||
fileWriter,
|
||||
offset - firstChunkOffset,
|
||||
chunkOptions.Range.Value().Length.Value(),
|
||||
static_cast<size_t>(chunkOptions.Range.Value().Length.Value()),
|
||||
context);
|
||||
|
||||
if (chunkId == numChunks - 1)
|
||||
@ -865,7 +869,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
|
||||
Azure::Response<Models::UploadFileFromResult> ShareFileClient::UploadFrom(
|
||||
const uint8_t* buffer,
|
||||
std::size_t bufferSize,
|
||||
size_t bufferSize,
|
||||
const UploadFileFromOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
{
|
||||
@ -949,7 +953,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
};
|
||||
|
||||
int64_t chunkSize = options.TransferOptions.ChunkSize;
|
||||
if (bufferSize < static_cast<std::size_t>(options.TransferOptions.SingleUploadThreshold))
|
||||
if (bufferSize < static_cast<size_t>(options.TransferOptions.SingleUploadThreshold))
|
||||
{
|
||||
chunkSize = bufferSize;
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
TEST_F(FileShareFileClientTest, ConcurrentUpload)
|
||||
{
|
||||
std::vector<uint8_t> fileContent = RandomBuffer(static_cast<std::size_t>(8_MB));
|
||||
std::vector<uint8_t> fileContent = RandomBuffer(static_cast<size_t>(8_MB));
|
||||
|
||||
auto testUploadFromBuffer = [&](int concurrency, int64_t fileSize) {
|
||||
auto fileClient = m_fileShareDirectoryClient->GetFileClient(RandomString());
|
||||
@ -339,18 +339,17 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
options.HttpHeaders = GetInterestingHttpHeaders();
|
||||
options.Metadata = RandomMetadata();
|
||||
|
||||
auto res
|
||||
= fileClient.UploadFrom(fileContent.data(), static_cast<std::size_t>(fileSize), options);
|
||||
auto res = fileClient.UploadFrom(fileContent.data(), static_cast<size_t>(fileSize), options);
|
||||
|
||||
auto properties = fileClient.GetProperties().Value;
|
||||
EXPECT_EQ(properties.FileSize, fileSize);
|
||||
EXPECT_EQ(properties.Metadata, options.Metadata);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
fileContent.begin(), fileContent.begin() + static_cast<std::size_t>(fileSize)));
|
||||
fileContent.begin(), fileContent.begin() + static_cast<size_t>(fileSize)));
|
||||
};
|
||||
|
||||
auto testUploadFromFile = [&](int concurrency, int64_t fileSize) {
|
||||
@ -365,7 +364,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::string tempFilename = RandomString();
|
||||
{
|
||||
Azure::Storage::_internal::FileWriter fileWriter(tempFilename);
|
||||
fileWriter.Write(fileContent.data(), fileSize, 0);
|
||||
fileWriter.Write(fileContent.data(), static_cast<size_t>(fileSize), 0);
|
||||
}
|
||||
|
||||
auto res = fileClient.UploadFrom(tempFilename, options);
|
||||
@ -373,12 +372,12 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto properties = fileClient.GetProperties().Value;
|
||||
EXPECT_EQ(properties.FileSize, fileSize);
|
||||
EXPECT_EQ(properties.Metadata, options.Metadata);
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize));
|
||||
EXPECT_EQ(
|
||||
downloadContent,
|
||||
std::vector<uint8_t>(
|
||||
fileContent.begin(), fileContent.begin() + static_cast<std::size_t>(fileSize)));
|
||||
fileContent.begin(), fileContent.begin() + static_cast<size_t>(fileSize)));
|
||||
|
||||
DeleteFile(tempFilename);
|
||||
};
|
||||
@ -388,7 +387,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
for (int64_t l : {0ULL, 512ULL, 1_KB, 4_KB, 1_MB, 4_MB + 512})
|
||||
{
|
||||
ASSERT_GE(fileContent.size(), static_cast<std::size_t>(l));
|
||||
ASSERT_GE(fileContent.size(), static_cast<size_t>(l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromBuffer, c, l));
|
||||
futures.emplace_back(std::async(std::launch::async, testUploadFromFile, c, l));
|
||||
}
|
||||
@ -442,7 +441,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
expectedData.clear();
|
||||
}
|
||||
}
|
||||
downloadBuffer.resize(static_cast<std::size_t>(downloadSize), '\x00');
|
||||
downloadBuffer.resize(static_cast<size_t>(downloadSize), '\x00');
|
||||
Files::Shares::DownloadFileToOptions options;
|
||||
options.TransferOptions.Concurrency = concurrency;
|
||||
if (offset.HasValue())
|
||||
@ -464,7 +463,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
auto res = m_fileClient->DownloadTo(downloadBuffer.data(), downloadBuffer.size(), options);
|
||||
EXPECT_EQ(res.Value.ContentRange.Length.Value(), actualDownloadSize);
|
||||
downloadBuffer.resize(static_cast<std::size_t>(res.Value.ContentRange.Length.Value()));
|
||||
downloadBuffer.resize(static_cast<size_t>(res.Value.ContentRange.Length.Value()));
|
||||
EXPECT_EQ(downloadBuffer, expectedData);
|
||||
}
|
||||
else
|
||||
@ -605,11 +604,11 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
for (int64_t length : {1ULL, 2ULL, 4_KB, 5_KB, 8_KB, 11_KB, 20_KB})
|
||||
{
|
||||
std::vector<uint8_t> downloadBuffer;
|
||||
downloadBuffer.resize(static_cast<std::size_t>(length - 1));
|
||||
downloadBuffer.resize(static_cast<size_t>(length - 1));
|
||||
options.Range.Value().Length = length;
|
||||
EXPECT_THROW(
|
||||
m_fileClient->DownloadTo(
|
||||
downloadBuffer.data(), static_cast<std::size_t>(length - 1), options),
|
||||
downloadBuffer.data(), static_cast<size_t>(length - 1), options),
|
||||
std::runtime_error);
|
||||
}
|
||||
}
|
||||
@ -725,9 +724,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
fileClient.Create(fileSize);
|
||||
EXPECT_NO_THROW(fileClient.UploadRange(0, memBodyStream));
|
||||
EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2));
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
EXPECT_NO_THROW(
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize)));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
EXPECT_NO_THROW(fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize)));
|
||||
EXPECT_EQ(halfContent, downloadContent);
|
||||
|
||||
EXPECT_NO_THROW(fileClient.ClearRange(512, 512));
|
||||
@ -755,9 +753,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
fileClient.Create(fileSize);
|
||||
EXPECT_NO_THROW(fileClient.UploadRange(0, memBodyStream));
|
||||
EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2));
|
||||
std::vector<uint8_t> downloadContent(static_cast<std::size_t>(fileSize), '\x00');
|
||||
EXPECT_NO_THROW(
|
||||
fileClient.DownloadTo(downloadContent.data(), static_cast<std::size_t>(fileSize)));
|
||||
std::vector<uint8_t> downloadContent(static_cast<size_t>(fileSize), '\x00');
|
||||
EXPECT_NO_THROW(fileClient.DownloadTo(downloadContent.data(), static_cast<size_t>(fileSize)));
|
||||
EXPECT_EQ(halfContent, downloadContent);
|
||||
|
||||
auto snapshot1 = m_shareClient->CreateSnapshot().Value.Snapshot;
|
||||
|
||||
@ -45,8 +45,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto fileClient = Files::Shares::ShareFileClient(fileUrl + sas);
|
||||
auto downloadedContent = fileClient.Download();
|
||||
EXPECT_EQ(
|
||||
ReadBodyStream(downloadedContent.Value.BodyStream).size(),
|
||||
static_cast<std::size_t>(fileSize));
|
||||
ReadBodyStream(downloadedContent.Value.BodyStream).size(), static_cast<size_t>(fileSize));
|
||||
};
|
||||
|
||||
auto verifyFileCreate = [&](const std::string& sas) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user