Upload FastSeekWpf/Core/CacheManager.cs
Browse files
FastSeekWpf/Core/CacheManager.cs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
using System;
|
| 2 |
using System.Collections.Generic;
|
| 3 |
using System.IO;
|
| 4 |
-
using System.IO.Compression;
|
| 5 |
using System.Text;
|
| 6 |
using System.Text.Json;
|
| 7 |
using System.Text.Json.Serialization;
|
| 8 |
-
using K4os.Compression.LZ4
|
| 9 |
|
| 10 |
namespace FastSeekWpf.Core;
|
| 11 |
|
|
@@ -36,14 +35,8 @@ public static class CacheManager
|
|
| 36 |
var cache = store.ToCache();
|
| 37 |
string json = JsonSerializer.Serialize(cache, JsonOptions);
|
| 38 |
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
using (var lz4 = new LZ4Stream(ms, LZ4Mode.HighCompression, LZ4StreamFlags.IsolateInnerStream))
|
| 42 |
-
{
|
| 43 |
-
lz4.Write(bytes, 0, bytes.Length);
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
File.WriteAllBytes(CachePath, ms.ToArray());
|
| 47 |
}
|
| 48 |
|
| 49 |
public static CacheData? LoadCache()
|
|
@@ -53,10 +46,8 @@ public static class CacheManager
|
|
| 53 |
try
|
| 54 |
{
|
| 55 |
byte[] compressed = File.ReadAllBytes(CachePath);
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
using var reader = new StreamReader(lz4, Encoding.UTF8);
|
| 59 |
-
string json = reader.ReadToEnd();
|
| 60 |
return JsonSerializer.Deserialize<CacheData>(json, JsonOptions);
|
| 61 |
}
|
| 62 |
catch
|
|
|
|
| 1 |
using System;
|
| 2 |
using System.Collections.Generic;
|
| 3 |
using System.IO;
|
|
|
|
| 4 |
using System.Text;
|
| 5 |
using System.Text.Json;
|
| 6 |
using System.Text.Json.Serialization;
|
| 7 |
+
using K4os.Compression.LZ4;
|
| 8 |
|
| 9 |
namespace FastSeekWpf.Core;
|
| 10 |
|
|
|
|
| 35 |
var cache = store.ToCache();
|
| 36 |
string json = JsonSerializer.Serialize(cache, JsonOptions);
|
| 37 |
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
| 38 |
+
byte[] compressed = LZ4Pickler.Pickle(bytes, LZ4Level.L12_MAX);
|
| 39 |
+
File.WriteAllBytes(CachePath, compressed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
public static CacheData? LoadCache()
|
|
|
|
| 46 |
try
|
| 47 |
{
|
| 48 |
byte[] compressed = File.ReadAllBytes(CachePath);
|
| 49 |
+
byte[] bytes = LZ4Pickler.Unpickle(compressed);
|
| 50 |
+
string json = Encoding.UTF8.GetString(bytes);
|
|
|
|
|
|
|
| 51 |
return JsonSerializer.Deserialize<CacheData>(json, JsonOptions);
|
| 52 |
}
|
| 53 |
catch
|