PageBlobWriteStream
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Shared;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace Azure.Storage.Blobs
{
internal class PageBlobWriteStream : StorageWriteStream
{
private readonly PageBlobClient _pageBlobClient;
private readonly PageBlobRequestConditions _conditions;
private long _writeIndex;
public PageBlobWriteStream(PageBlobClient pageBlobClient, long bufferSize, long position, PageBlobRequestConditions conditions, IProgress<long> progressHandler, UploadTransferValidationOptions transferValidation)
: base(position, bufferSize, progressHandler, transferValidation, null, null)
{
ValidateBufferSize(bufferSize);
ValidatePosition(position);
_pageBlobClient = pageBlobClient;
_conditions = (conditions ?? new PageBlobRequestConditions());
_writeIndex = position;
}
[AsyncStateMachine(typeof(<AppendInternal>d__4))]
protected override Task AppendInternal(UploadTransferValidationOptions validationOptions, bool async, CancellationToken cancellationToken)
{
<AppendInternal>d__4 stateMachine = default(<AppendInternal>d__4);
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.validationOptions = validationOptions;
stateMachine.async = async;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
protected override void ValidateBufferSize(long bufferSize)
{
if (bufferSize < 1)
throw new ArgumentOutOfRangeException("bufferSize", "Must be greater than or equal to 1");
if (bufferSize > 4194304)
throw new ArgumentOutOfRangeException("bufferSize", $"""{4194304}");
if (bufferSize % 512 != 0)
throw new ArgumentOutOfRangeException("bufferSize", $"""{512}");
}
private static void ValidatePosition(long position)
{
if (position % 512 != 0)
throw new ArgumentOutOfRangeException("position", $"""{512}");
}
}
}