From 60d531834836f422d9c15edc67742afb6320b469 Mon Sep 17 00:00:00 2001
From: 7H3LaughingMan <7H3LaughingMan@proton.me>
Date: Tue, 22 Apr 2025 11:43:01 -0500
Subject: [PATCH] Add ZStd Support - Uses ZstdSharp.Port
---
src/DotTiled/DotTiled.csproj | 4 ++++
src/DotTiled/Serialization/Helpers.cs | 6 ++++++
src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs | 8 +++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/DotTiled/DotTiled.csproj b/src/DotTiled/DotTiled.csproj
index 6e8de2a..c91aeac 100644
--- a/src/DotTiled/DotTiled.csproj
+++ b/src/DotTiled/DotTiled.csproj
@@ -26,4 +26,8 @@
+
+
+
+
diff --git a/src/DotTiled/Serialization/Helpers.cs b/src/DotTiled/Serialization/Helpers.cs
index d716293..2038401 100644
--- a/src/DotTiled/Serialization/Helpers.cs
+++ b/src/DotTiled/Serialization/Helpers.cs
@@ -46,6 +46,12 @@ internal static partial class Helpers
return ReadMemoryStreamAsInt32Array(decompressedStream);
}
+ internal static uint[] DecompressZStd(MemoryStream stream)
+ {
+ using var decompressedStream = new ZstdSharp.DecompressionStream(stream);
+ return ReadMemoryStreamAsInt32Array(decompressedStream);
+ }
+
internal static uint[] ReadBytesAsInt32Array(byte[] bytes)
{
var intArray = new uint[bytes.Length / 4];
diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs
index a05bbd0..6df7942 100644
--- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs
+++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs
@@ -78,7 +78,7 @@ public abstract partial class TmxReaderBase
{
DataCompression.GZip => DecompressGZip(bytes),
DataCompression.ZLib => DecompressZLib(bytes),
- DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."),
+ DataCompression.ZStd => DecompressZStd(bytes),
_ => throw new XmlException("Invalid compression")
};
@@ -117,4 +117,10 @@ public abstract partial class TmxReaderBase
using var decompressedStream = new ZLibStream(stream, CompressionMode.Decompress);
return ReadMemoryStreamAsInt32Array(decompressedStream);
}
+
+ internal static uint[] DecompressZStd(MemoryStream stream)
+ {
+ using var decompressedStream = new ZstdSharp.DecompressionStream(stream);
+ return ReadMemoryStreamAsInt32Array(decompressedStream);
+ }
}