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

Blockprocessor.cs « Main « Library « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa8d8e75ae0632c6961a9a860a314c4704cfd632 (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
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Duplicati.Library.Main
{
    public class Blockprocessor : IDisposable
    {
        private Stream m_stream;
        private byte[] m_buffer;
        private bool m_depleted = false;

        public Blockprocessor(Stream stream, byte[] buffer)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            if (buffer == null)
                throw new ArgumentNullException("buffer");

            m_stream = stream;
            m_buffer = buffer;
        }

        public int Readblock()
        {
            if (m_depleted)
                return 0;
            
            var bytesleft = m_buffer.Length;
            var bytesread = 0;
            var read = 1;

            while (bytesleft > 0 && read > 0)
            {
                read = m_stream.Read(m_buffer, bytesread, bytesleft);
                bytesleft -= read;
                bytesread += read;
            }

            m_depleted = bytesleft != 0;

            return bytesread;
        }
        
        public long Length { get { return m_stream.Length; } }

        public void Dispose()
        {
            if (m_stream != null)
                m_stream.Dispose();
            m_stream = null;
            m_buffer = null;
        }
    }
}