ZStd Support

This commit is contained in:
7H3LaughingMan 2025-04-29 14:24:45 -05:00
parent 4e735ad8f3
commit 2388af6b52
4 changed files with 9 additions and 2 deletions

View file

@ -46,6 +46,12 @@ internal static partial class Helpers
return ReadMemoryStreamAsInt32Array(decompressedStream); 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) internal static uint[] ReadBytesAsInt32Array(byte[] bytes)
{ {
var intArray = new uint[bytes.Length / 4]; var intArray = new uint[bytes.Length / 4];

View file

@ -61,7 +61,7 @@ public abstract partial class TmjReaderBase
{ {
DataCompression.GZip => Helpers.DecompressGZip(stream), DataCompression.GZip => Helpers.DecompressGZip(stream),
DataCompression.ZLib => Helpers.DecompressZLib(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}'.") _ => throw new InvalidOperationException($"Unsupported compression '{compression}'.")
}; };

View file

@ -16,6 +16,7 @@ public abstract partial class TmjReaderBase
{ {
"zlib" => DataCompression.ZLib, "zlib" => DataCompression.ZLib,
"gzip" => DataCompression.GZip, "gzip" => DataCompression.GZip,
"zstd" => DataCompression.ZStd,
"" => Optional.Empty, "" => Optional.Empty,
_ => throw new JsonException($"Unsupported compression '{s}'.") _ => throw new JsonException($"Unsupported compression '{s}'.")
}); });

View file

@ -77,7 +77,7 @@ public abstract partial class TmxReaderBase
{ {
DataCompression.GZip => Helpers.DecompressGZip(bytes), DataCompression.GZip => Helpers.DecompressGZip(bytes),
DataCompression.ZLib => Helpers.DecompressZLib(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") _ => throw new XmlException("Invalid compression")
}; };