using System.IO; using Duplicati.Library.Utility; namespace Duplicati.Library.Backend { /// /// Private helper class to fix a bug with the StreamReader /// internal class StreamReadHelper : OverrideableStream { /// /// Once the stream has returned 0 as the read count it is disposed, /// and subsequent read requests will throw an ObjectDisposedException /// private bool m_empty; /// /// Basic initialization, just pass the stream to the super class /// /// public StreamReadHelper(Stream stream) : base(stream) { } /// /// Override the read function to make sure that we only return less than the requested amount of data if the stream is exhausted /// /// The buffer to place data in /// The offset into the buffer to start at /// The number of bytes to read /// The number of bytes read public override int Read(byte[] buffer, int offset, int count) { var readCount = 0; int a; while (!m_empty && count > 0) { a = base.Read(buffer, offset, count); readCount += a; count -= a; offset += a; m_empty = a == 0; } return readCount; } } }