-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileDataBlock.cs
96 lines (81 loc) · 2.35 KB
/
FileDataBlock.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
namespace Be.Windows.Forms
{
internal sealed class FileDataBlock : DataBlock
{
long _length;
long _fileOffset;
public FileDataBlock(long fileOffset, long length)
{
_fileOffset = fileOffset;
_length = length;
}
public long FileOffset
{
get
{
return _fileOffset;
}
}
public override long Length
{
get
{
return _length;
}
}
public void SetFileOffset(long value)
{
_fileOffset = value;
}
public void RemoveBytesFromEnd(long count)
{
if (count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
_length -= count;
}
public void RemoveBytesFromStart(long count)
{
if (count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
_fileOffset += count;
_length -= count;
}
public override void RemoveBytes(long position, long count)
{
if (position > _length)
{
throw new ArgumentOutOfRangeException("position");
}
if (position + count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
long prefixLength = position;
long prefixFileOffset = _fileOffset;
long suffixLength = _length - count - prefixLength;
long suffixFileOffset = _fileOffset + position + count;
if (prefixLength > 0 && suffixLength > 0)
{
_fileOffset = prefixFileOffset;
_length = prefixLength;
_map.AddAfter(this, new FileDataBlock(suffixFileOffset, suffixLength));
return;
}
if (prefixLength > 0)
{
_fileOffset = prefixFileOffset;
_length = prefixLength;
}
else
{
_fileOffset = suffixFileOffset;
_length = suffixLength;
}
}
}
}