-
Notifications
You must be signed in to change notification settings - Fork 1
/
DirectoryHashEntry.cs
40 lines (38 loc) · 1.27 KB
/
DirectoryHashEntry.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace de.intronik.backup
{
public class DirectoryHashEntry : HashEntry
{
byte[] _cachedHash;
public Dictionary<string, HashEntry> Entries { get; private set; }
public string Name { get; private set; }
public DirectoryHashEntry(string name, int capacity)
{
this.Name = name;
this.Entries = new Dictionary<string, HashEntry>(capacity, StringComparer.Ordinal);
}
protected override bool GetIsDirectory() { return true; }
protected override byte[] GetHash()
{
if (this._cachedHash != null)
return this._cachedHash;
using (var m = new MemoryStream())
{
var w = new BinaryWriter(m);
// write virtual folder structure
foreach (var subEntry in this.Entries)
{
w.Write(subEntry.Value.IsDirectory);
w.Write(subEntry.Value.Hash);
w.Write(subEntry.Key);
}
// compute hash
return this._cachedHash = HashProvider.ComputeHash(m.ToArray());
}
}
}
}