Skip to content

Commit

Permalink
Dispose of streams that are created (#44510)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewSteeples authored Oct 4, 2024
1 parent 335b888 commit 4607949
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
38 changes: 24 additions & 14 deletions sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,18 @@ public virtual Response<BlobContentInfo> Upload(
public virtual Response<BlobContentInfo> Upload(
BinaryData content,
BlobUploadOptions options,
CancellationToken cancellationToken = default) =>
StagedUploadInternal(
content.ToStream(),
options,
async: false,
cancellationToken: cancellationToken)
.EnsureCompleted();
CancellationToken cancellationToken = default)
{
using (var stream = content.ToStream())
{
return StagedUploadInternal(
stream,
options,
async: false,
cancellationToken: cancellationToken)
.EnsureCompleted();
}
}

/// <summary>
/// The <see cref="Upload(Stream, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, AccessTier?, StorageTransferOptions, CancellationToken)"/>
Expand Down Expand Up @@ -1360,13 +1365,18 @@ await StagedUploadInternal(
public virtual async Task<Response<BlobContentInfo>> UploadAsync(
BinaryData content,
BlobUploadOptions options,
CancellationToken cancellationToken = default) =>
await StagedUploadInternal(
content.ToStream(),
options,
async: true,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using (var stream = content.ToStream())
{
return await StagedUploadInternal(
stream,
options,
async: true,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
}

/// <summary>
/// The <see cref="UploadAsync(Stream, BlobHttpHeaders, Metadata, BlobRequestConditions, IProgress{long}, AccessTier?, StorageTransferOptions, CancellationToken)"/>
Expand Down
20 changes: 12 additions & 8 deletions sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3238,14 +3238,18 @@ await client.StageBlockInternal(
LeaseId = args.Conditions.LeaseId
};
}
await client.StageBlockInternal(
Shared.StorageExtensions.GenerateBlockId(offset),
content.ToStream(),
validationOptions,
conditions,
progressHandler,
async,
cancellationToken).ConfigureAwait(false);

using (var stream = content.ToStream())
{
await client.StageBlockInternal(
Shared.StorageExtensions.GenerateBlockId(offset),
stream,
validationOptions,
conditions,
progressHandler,
async,
cancellationToken).ConfigureAwait(false);
}
},
CommitPartitionedUpload = async (partitions, args, async, cancellationToken)
=> await client.CommitBlockListInternal(
Expand Down

0 comments on commit 4607949

Please sign in to comment.