forked from ironfede/openmcdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSector.cs
48 lines (41 loc) · 1.16 KB
/
Sector.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
using System.Diagnostics.CodeAnalysis;
namespace OpenMcdf;
/// <summary>
/// Encapsulates information about a sector in a compound file.
/// </summary>
/// <param name="Id">The sector ID</param>
/// <param name="Length">The sector length</param>
internal record struct Sector(uint Id, int Length)
{
public static readonly Sector EndOfChain = new(SectorType.EndOfChain, 0);
public readonly bool IsValid => Id <= SectorType.Maximum;
/// <summary>
/// The position of the sector in the compound file stream.
/// </summary>
public readonly long Position
{
get
{
ThrowIfInvalid();
return (Id + 1) * Length;
}
}
/// <summary>
/// The end position of the sector in the compound file stream.
/// </summary>
public readonly long EndPosition
{
get
{
ThrowIfInvalid();
return (Id + 2) * Length;
}
}
readonly void ThrowIfInvalid()
{
if (!IsValid)
throw new InvalidOperationException($"Invalid FAT sector ID: {Id}.");
}
[ExcludeFromCodeCoverage]
public override readonly string ToString() => $"{Id}";
}