blob: 83fbdf7ea8777d4373845f3e170b13319c5ebe11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.MachineStudio.Common.Update
{
/// <summary>
/// Represents a FileStream Wrapper dedicated for delivering Read/Write progress callbacks.
/// </summary>
/// <seealso cref="System.IO.FileStream" />
public class FileStreamWrapper : FileStream
{
private Action<long> _callback;
/// <summary>
/// Initializes a new instance of the <see cref="FileStreamWrapper"/> class.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <param name="mode">The mode.</param>
/// <param name="callback">The callback.</param>
public FileStreamWrapper(String fileName, FileMode mode, Action<long> callback) : base(fileName, mode)
{
_callback = callback;
}
/// <summary>
/// Writes a block of bytes to the file stream.
/// </summary>
/// <param name="array">The buffer containing data to write to the stream.</param>
/// <param name="offset">The zero-based byte offset in <paramref name="array" /> from which to begin copying bytes to the stream.</param>
/// <param name="count">The maximum number of bytes to write.</param>
public override void Write(byte[] array, int offset, int count)
{
_callback?.Invoke(Length);
base.Write(array, offset, count);
}
/// <summary>
/// Reads a block of bytes from the stream and writes the data in a given buffer.
/// </summary>
/// <param name="array">When this method returns, contains the specified byte array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + <paramref name="count" /> - 1<paramref name=")" /> replaced by the bytes read from the current source.</param>
/// <param name="offset">The byte offset in <paramref name="array" /> at which the read bytes will be placed.</param>
/// <param name="count">The maximum number of bytes to read.</param>
/// <returns>
/// 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.
/// </returns>
public override int Read(byte[] array, int offset, int count)
{
_callback?.Invoke(Position);
return base.Read(array, offset, count);
}
}
}
|