using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.MachineStudio.Common.Update { /// /// Represents a FileStream Wrapper dedicated for delivering Read/Write progress callbacks. /// /// public class FileStreamWrapper : FileStream { private Action _callback; /// /// Initializes a new instance of the class. /// /// Name of the file. /// The mode. /// The callback. public FileStreamWrapper(String fileName, FileMode mode, Action callback) : base(fileName, mode) { _callback = callback; } /// /// Writes a block of bytes to the file stream. /// /// The buffer containing data to write to the stream. /// The zero-based byte offset in from which to begin copying bytes to the stream. /// The maximum number of bytes to write. public override void Write(byte[] array, int offset, int count) { _callback?.Invoke(Length); base.Write(array, offset, count); } /// /// Reads a block of bytes from the stream and writes the data in a given buffer. /// /// When this method returns, contains the specified byte array with the values between and ( + - 1 replaced by the bytes read from the current source. /// The byte offset in at which the read bytes will be placed. /// The maximum number of bytes to read. /// /// The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached. /// public override int Read(byte[] array, int offset, int count) { _callback?.Invoke(Position); return base.Read(array, offset, count); } } }