using System; using System.IO; namespace Duplicati.Library.Compression { /// /// CompressionStream wrapper to prevent closing the base stream when disposing the entry stream /// public class StreamWrapper : Utility.OverrideableStream { /// /// The callback to invoke when the stream is disposed /// private readonly Action m_onCloseCallback; /// /// Initializes a new instance of the class. /// /// Stream. /// On close. public StreamWrapper(Stream stream, Action onClose) : base(stream) { m_onCloseCallback = onClose; } /// /// Disposes the stream, and calls the close handler if required /// /// If set to true, this call originates from the dispose method. protected override void Dispose(bool disposing) { if (!disposing || m_basestream == null) return; m_basestream.Dispose(); m_basestream = null; if (m_onCloseCallback != null) m_onCloseCallback(this); } public long GetSize() { return m_basestream == null ? 0 : m_basestream.Length; } } }