This is used so that a full hash check does not have to be performed the first time a torrent is started. Normally all the data for a torrent would be passed through a SHA1 hasher so that data integrity can be verified. With fast resume you can skip this step.
1 public void SaveFastResume (List <TorrentManager> managers)
2 {
3 // Store the fast resume for each torrent in a list,
4 // then serialise the list to the disk.
5 BEncodedList list = new BEncodedList ();
6 foreach (TorrentManager manager in managers) {
7
8 // Get the fast resume data for the torrent
9 FastResume data = manager.SaveFastResume ();
10
11 // Encode the FastResume data to a BEncodedDictionary.
12 BEncodedDictionary fastResume = data.Encode ();
13
14 // Add the FastResume dictionary to the main dictionary using
15 // the torrents infohash as the key
16 list.Add (data);
17 }
18
19 // Write all the fast resume data to disk
20 File.WriteAllBytes (fastResumePath, list.Encode ());
21 }
22
23 public void LoadFastResume (List <TorrentManager> managers)
24 {
25 // Read the main dictionary from disk and iterate through
26 // all the fast resume items
27 BEncodedList list = (BEncodedList) BEncodedValue.Decode (File.ReadAllBytes (fastResumePath));
28 foreach (BEncodedDictionary fastResume in list) {
29
30 // Decode the FastResume data from the BEncodedDictionary
31 FastResume data = new FastResume (fastResume);
32
33 // Find the torrentmanager that the fastresume belongs to
34 // and then load it
35 foreach (TorrentManager manager in managers)
36 if (manager.InfoHash == data.Infohash)
37 manager.LoadFastResume (data);
38 }
39 }