forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad01bac
commit f0265cb
Showing
170 changed files
with
74,491 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
sdk/storage/Azure.Storage.Blobs/src/AppendBlobWriteStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs.Models; | ||
using Azure.Storage.Blobs.Specialized; | ||
using Azure.Storage.Shared; | ||
|
||
namespace Azure.Storage.Blobs | ||
{ | ||
internal class AppendBlobWriteStream : StorageWriteStream | ||
{ | ||
private readonly AppendBlobClient _appendBlobClient; | ||
private readonly AppendBlobRequestConditions _conditions; | ||
|
||
public AppendBlobWriteStream( | ||
AppendBlobClient appendBlobClient, | ||
long bufferSize, | ||
long position, | ||
AppendBlobRequestConditions conditions, | ||
IProgress<long> progressHandler) : base( | ||
position, | ||
bufferSize, | ||
progressHandler) | ||
{ | ||
ValidateBufferSize(bufferSize); | ||
_appendBlobClient = appendBlobClient; | ||
_conditions = conditions ?? new AppendBlobRequestConditions(); | ||
} | ||
|
||
protected override async Task AppendInternal( | ||
bool async, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (_buffer.Length > 0) | ||
{ | ||
_buffer.Position = 0; | ||
|
||
Response<BlobAppendInfo> response = await _appendBlobClient.AppendBlockInternal( | ||
content: _buffer, | ||
transactionalContentHash: default, | ||
conditions: _conditions, | ||
progressHandler: _progressHandler, | ||
async: async, | ||
cancellationToken: cancellationToken) | ||
.ConfigureAwait(false); | ||
|
||
_conditions.IfMatch = response.Value.ETag; | ||
|
||
_buffer.Clear(); | ||
} | ||
} | ||
|
||
protected override async Task FlushInternal(bool async, CancellationToken cancellationToken) | ||
=> await AppendInternal(async, cancellationToken).ConfigureAwait(false); | ||
|
||
protected override void ValidateBufferSize(long bufferSize) | ||
{ | ||
if (bufferSize < 1) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(bufferSize), "Must be greater than or equal to 1"); | ||
} | ||
|
||
if (bufferSize > Constants.Blob.Append.MaxAppendBlockBytes) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(bufferSize), $"Must less than or equal to {Constants.Blob.Append.MaxAppendBlockBytes}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.