From eae7752e4ba8d79782386eece658c01cf442d098 Mon Sep 17 00:00:00 2001 From: Reuben Bond <203839+ReubenBond@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:57:04 -0700 Subject: [PATCH] NonDisposingStream: delegate remaining Stream APIs to inner stream (#38184) --- .../src/Shared/NonDisposingStream.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sdk/storage/Azure.Storage.Common/src/Shared/NonDisposingStream.cs b/sdk/storage/Azure.Storage.Common/src/Shared/NonDisposingStream.cs index adfefc06fffde..64ff1b2665020 100644 --- a/sdk/storage/Azure.Storage.Common/src/Shared/NonDisposingStream.cs +++ b/sdk/storage/Azure.Storage.Common/src/Shared/NonDisposingStream.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -21,6 +22,8 @@ internal class NonDisposingStream : Stream public override bool CanWrite => _innerStream.CanWrite; + public override bool CanTimeout => _innerStream.CanTimeout; + public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => _innerStream.CopyToAsync(destination, bufferSize, cancellationToken); public override long Length => _innerStream.Length; @@ -42,6 +45,36 @@ internal class NonDisposingStream : Stream public override void Write(byte[] buffer, int offset, int count) => _innerStream.Write(buffer, offset, count); public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _innerStream.WriteAsync(buffer, offset, count, cancellationToken); + + public override int ReadByte() => _innerStream.ReadByte(); + + public override void WriteByte(byte value) => _innerStream.WriteByte(value); + + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => _innerStream.BeginRead(buffer, offset, count, callback, state); + + public override int EndRead(IAsyncResult asyncResult) => _innerStream.EndRead(asyncResult); + + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => _innerStream.BeginWrite(buffer, offset, count, callback, state); + + public override void EndWrite(IAsyncResult asyncResult) => _innerStream.EndWrite(asyncResult); + + public override int ReadTimeout { get => _innerStream.ReadTimeout; set => _innerStream.ReadTimeout = value; } + + public override int WriteTimeout { get => _innerStream.WriteTimeout; set => _innerStream.WriteTimeout = value; } + +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER + + public override void CopyTo(Stream destination, int bufferSize) => _innerStream.CopyTo(destination, bufferSize); + + public override int Read(Span buffer) => _innerStream.Read(buffer); + + public override void Write(ReadOnlySpan buffer) => _innerStream.Write(buffer); + + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) => _innerStream.WriteAsync(buffer, cancellationToken); + + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) => _innerStream.ReadAsync(buffer, cancellationToken); + +#endif } internal static partial class StreamExtensions