-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastFileBinaryReader.cs
More file actions
100 lines (78 loc) · 2.94 KB
/
Copy pathFastFileBinaryReader.cs
File metadata and controls
100 lines (78 loc) · 2.94 KB
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
97
98
99
100
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace FastFilesCompressor
{
public class FastFileBinaryReader : BinaryReader
{
public FastFileBinaryReader(FileStream fileStream)
: base(fileStream) { }
public string ReadFixedSizeString(int size)
{
return Encoding.ASCII.GetString(ReadBytes(size));
}
public FastFileHeader ReadFastFileHeader()
{
FastFileHeader header = new FastFileHeader();
header.Signature = ReadFixedSizeString(8);
header.Version = ReadInt32();
header.Build = ReadInt32();
header.Depth = ReadInt32();
header.MaximumChunkSize = ReadInt32();
header.Zeros = ReadBytes(12);
return header;
}
public DeltaFastFileWrapper ReadDeltaFastFileWrapper()
{
DeltaFastFileWrapper deltaFastFileWrapper = new DeltaFastFileWrapper();
deltaFastFileWrapper.Header = ReadFastFileHeader();
deltaFastFileWrapper.Indirection = ReadBytes(20);
return deltaFastFileWrapper;
}
public FastFile ReadFastFile()
{
FastFile fastFile = new FastFile();
long numberOfEntries = ReadInt32();
List<byte[]> references = new List<byte[]>();
fastFile.References = references;
for(int i = 0; i < numberOfEntries; i++)
{
references.Add(ReadBytes(16));
}
fastFile.CompressedFileSize = ReadInt64();
ConfirmEquality(fastFile.CompressedFileSize, ReadInt64());
fastFile.UncompressedFileSize = ReadInt64();
fastFile.MetaData = ReadBytes(72);
ConfirmEquality(fastFile.UncompressedFileSize, ReadInt64());
fastFile.CompressionType = ReadInt32();
return fastFile;
}
public DeltaFastFile ReadDeltaFastFile()
{
DeltaFastFile fastFile = new DeltaFastFile();
long numberOfEntries = ReadInt32();
fastFile.CompressedFileSize = ReadInt64();
ConfirmEquality(fastFile.CompressedFileSize, ReadInt64());
fastFile.InitialMetaData = ReadBytes(40);
fastFile.UncompressedFileSize = ReadInt64();
List<byte[]> references = new List<byte[]>();
fastFile.References = references;
for (int i = 0; i < numberOfEntries; i++)
{
references.Add(ReadBytes(16));
}
fastFile.MetaData = ReadBytes(80);
ConfirmEquality(fastFile.UncompressedFileSize, ReadInt64());
fastFile.CompressionType = ReadInt32();
return fastFile;
}
private void ConfirmEquality(Int64 value, Int64 compared)
{
if (value != compared)
{
throw new InvalidDataException();
}
}
}
}