// Copyright (C) 2025, The Duplicati Team // https://duplicati.com, hello@duplicati.com // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.IO; using System.Threading.Tasks; namespace Duplicati.Library.Utility { /// /// This class is a wrapper for a stream. /// It's only purpose is to free other wrappers from implementing the boilerplate functions, /// and allow the derived classes to override single functions. /// public class OverrideableStream : Stream { /// /// The base stream that is wrapped /// protected Stream m_basestream; /// /// Creates a new instance /// /// The stream to wrap /// public OverrideableStream(Stream basestream) { m_basestream = basestream ?? throw new ArgumentNullException(nameof(basestream)); } /// public override bool CanRead => m_basestream.CanRead; /// public override bool CanSeek => m_basestream.CanSeek; /// public override bool CanWrite => m_basestream.CanWrite; /// public override void Flush() => m_basestream.Flush(); /// public override long Length => m_basestream.Length; /// public override long Position { get => m_basestream.Position; set => m_basestream.Position = value; } /// public override int Read(byte[] buffer, int offset, int count) => m_basestream.Read(buffer, offset, count); /// public override long Seek(long offset, System.IO.SeekOrigin origin) => m_basestream.Seek(offset, origin); /// public override void SetLength(long value) => m_basestream.SetLength(value); /// public override void Write(byte[] buffer, int offset, int count) => m_basestream.Write(buffer, offset, count); /// public override Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) => m_basestream.ReadAsync(buffer, offset, count, cancellationToken); /// public override Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) => m_basestream.WriteAsync(buffer, offset, count, cancellationToken); /// public override Task FlushAsync(System.Threading.CancellationToken cancellationToken) => m_basestream.FlushAsync(cancellationToken); /// protected override void Dispose(bool disposing) { m_basestream?.Dispose(); m_basestream = null; base.Dispose(disposing); } } }