-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileReader.cs
36 lines (35 loc) · 1.08 KB
/
FileReader.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
using System.IO;
using BSU.Sync.FileTypes;
using Newtonsoft.Json;
using NLog;
namespace BSU.Sync
{
internal static class FileReader
{
internal static Logger Logger = LogManager.GetCurrentClassLogger();
internal static ServerFile ReadServerFileFromStream(Stream s)
{
var js = new JsonSerializer();
using (TextReader tr = new StreamReader(s))
{
try
{
return (ServerFile)js.Deserialize(tr, typeof(ServerFile));
}
catch (JsonReaderException e)
{
Logger.Error(e, "Failed to deserialize server file");
return null;
}
}
}
internal static HashFile ReadHashFileFromStream(Stream s)
{
JsonSerializer js = new JsonSerializer();
using (TextReader tr = new StreamReader(s))
{
return (HashFile)js.Deserialize(tr, typeof(HashFile));
}
}
}
}