Add ZStd Support - Uses ZstdSharp.Port

This commit is contained in:
7H3LaughingMan 2025-04-22 11:43:01 -05:00
parent 7f78a971f9
commit 60d5318348
3 changed files with 17 additions and 1 deletions

View file

@ -26,4 +26,8 @@
<None Include="../../LICENSE" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ZstdSharp.Port" Version="0.8.5" />
</ItemGroup>
</Project>

View file

@ -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];

View file

@ -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);
}
}