diff --git a/src/DotTiled/Serialization/Helpers.cs b/src/DotTiled/Serialization/Helpers.cs index 28d6aec..0e7e51c 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/Tmj/TmjReaderBase.Data.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs index 904321b..9d1e5db 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.Data.cs @@ -61,7 +61,7 @@ public abstract partial class TmjReaderBase { DataCompression.GZip => Helpers.DecompressGZip(stream), DataCompression.ZLib => Helpers.DecompressZLib(stream), - DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."), + DataCompression.ZStd => Helpers.DecompressZStd(stream), _ => throw new InvalidOperationException($"Unsupported compression '{compression}'.") }; diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs index 862df4d..22d65b6 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.TileLayer.cs @@ -16,6 +16,7 @@ public abstract partial class TmjReaderBase { "zlib" => DataCompression.ZLib, "gzip" => DataCompression.GZip, + "zstd" => DataCompression.ZStd, "" => Optional.Empty, _ => throw new JsonException($"Unsupported compression '{s}'.") }); diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs index e60f641..a01a582 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.Data.cs @@ -77,7 +77,7 @@ public abstract partial class TmxReaderBase { DataCompression.GZip => Helpers.DecompressGZip(bytes), DataCompression.ZLib => Helpers.DecompressZLib(bytes), - DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."), + DataCompression.ZStd => Helpers.DecompressZStd(bytes), _ => throw new XmlException("Invalid compression") };