Added Compression to Ceras serialization

This commit is contained in:
erri120 2019-10-27 13:11:10 +01:00
parent 6fd9d49c9e
commit 4c694eafc9
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135

View File

@ -193,9 +193,9 @@ namespace Wabbajack.Common
return new DynamicIniData(new FileIniDataParser().ReadData(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(file)))));
}
public static void ToCERAS<T>(this T obj, string filename)
public static void ToCERAS<T>(this T obj, string filename, ref SerializerConfig config)
{
var ceras = new CerasSerializer();
var ceras = new CerasSerializer(config);
byte[] buffer = null;
ceras.Serialize(obj, ref buffer);
using(var m1 = new MemoryStream(buffer))
@ -207,6 +207,19 @@ namespace Wabbajack.Common
}
}
public static T FromCERAS<T>(this Stream data, ref SerializerConfig config)
{
var ceras = new CerasSerializer(config);
byte[] bytes = data.ReadAll();
using (var m1 = new MemoryStream(bytes))
using (var m2 = new MemoryStream())
{
BZip2.Decompress(m1, m2, false);
m2.Seek(0, SeekOrigin.Begin);
return ceras.Deserialize<T>(m2.ToArray());
}
}
public static void ToJSON<T>(this T obj, string filename)
{
File.WriteAllText(filename,
@ -267,19 +280,6 @@ namespace Wabbajack.Common
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
}
public static T FromCERAS<T>(this Stream data)
{
var ceras = new CerasSerializer();
byte[] bytes = data.ReadAll();
using (var m1 = new MemoryStream(bytes))
using (var m2 = new MemoryStream())
{
BZip2.Decompress(m1, m2, false);
m2.Seek(0, SeekOrigin.Begin);
return ceras.Deserialize<T>(m2.ToArray());
}
}
public static bool FileExists(this string filename)
{
return File.Exists(filename);