mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added Compression to Ceras serialization
This commit is contained in:
parent
6fd9d49c9e
commit
4c694eafc9
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user