Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TrackableFileStream.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ff953ddc2a629aac14de737b80818bf7269868b (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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace com.clusterrr.util
{
    public class TrackableFileStream : FileStream
    {
        public delegate void OnProgressDelegate(long Position, long Length);
        public event OnProgressDelegate OnProgress = delegate { };

        public TrackableFileStream(string path, FileMode mode) : base(path, mode) { }

        public override void Write(byte[] array, int offset, int count)
        {
            base.Write(array, offset, count);
            OnProgress(this.Position, this.Length);
        }
        public override void WriteByte(byte value)
        {
            base.WriteByte(value);
            OnProgress(this.Position, this.Length);
        }
        public override int Read(byte[] array, int offset, int count)
        {
            var r = base.Read(array, offset, count);
            OnProgress(this.Position, this.Length);
            return r;
        }
        public override int ReadByte()
        {
            var r = base.ReadByte();
            OnProgress(this.Position, this.Length);
            return r;
        }
    }
}