Skip to content

Commit f68144f

Browse files
fix(v2.1): re-enable Zstd on net11 - .NET 11 RC1 DOES ship ZstandardStream
Previous commit wrongly disabled Zstd: the ref-pack XML search missed the type, but reflection against System.IO.Compression.dll (11.0.0-rc.1) confirms ZstandardStream(Stream, CompressionLevel, bool) and ZstandardCompressionOptions exist. Restore the original #if NET11_0_OR_GREATER implementation; Zstd tests now pass on net11 (0 skipped). net10.0 unchanged (PlatformNotSupportedException fallback, 1679 tests green).
1 parent 3a88dbe commit f68144f

3 files changed

Lines changed: 12 additions & 35 deletions

File tree

‎src/SharpCoreDB/Services/BlockCompressor.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,25 @@ public static byte[] Decompress(ReadOnlySpan<byte> data, BlockCompressionMode mo
5555
{
5656
BlockCompressionMode.Brotli => new BrotliStream(output, level, leaveOpen: false),
5757
BlockCompressionMode.GZip => new GZipStream(output, level, leaveOpen: false),
58+
#if NET11_0_OR_GREATER
59+
BlockCompressionMode.Zstd => new ZstandardStream(output, level, leaveOpen: false),
60+
#else
5861
BlockCompressionMode.Zstd => throw new PlatformNotSupportedException(
59-
"Zstd compression is not available in the current .NET runtime (System.IO.Compression does not ship a Zstandard stream yet)."),
62+
"Zstd compression requires .NET 11 or later. Current runtime: " + Environment.Version),
63+
#endif
6064
_ => throw new ArgumentOutOfRangeException(nameof(mode))
6165
};
6266

6367
private static Stream CreateDecompressor(Stream input, BlockCompressionMode mode) => mode switch
6468
{
6569
BlockCompressionMode.Brotli => new BrotliStream(input, CompressionMode.Decompress, leaveOpen: false),
6670
BlockCompressionMode.GZip => new GZipStream(input, CompressionMode.Decompress, leaveOpen: false),
71+
#if NET11_0_OR_GREATER
72+
BlockCompressionMode.Zstd => new ZstandardStream(input, CompressionMode.Decompress, leaveOpen: false),
73+
#else
6774
BlockCompressionMode.Zstd => throw new PlatformNotSupportedException(
68-
"Zstd decompression is not available in the current .NET runtime (System.IO.Compression does not ship a Zstandard stream yet)."),
75+
"Zstd decompression requires .NET 11 or later. Current runtime: " + Environment.Version),
76+
#endif
6977
_ => throw new ArgumentOutOfRangeException(nameof(mode))
7078
};
7179

‎src/SharpCoreDB/Storage/BlockCompressionMode.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public enum BlockCompressionMode
3030
/// <summary>
3131
/// Zstandard compression (excellent speed/ratio balance).
3232
/// Best for: general-purpose database blocks, telemetry, mixed workloads.
33-
/// NOTE: .NET 11 RC1 does not ship a Zstandard stream in System.IO.Compression yet
34-
/// (only ZLib streams), so this mode currently throws PlatformNotSupportedException
35-
/// on all runtimes; it is reserved for a future runtime that adds native Zstandard.
33+
/// Requires .NET 11+ (System.IO.Compression.ZstandardStream).
34+
/// On .NET 10, using this mode will throw NotSupportedException.
3635
/// </summary>
3736
Zstd = 3
3837
}

‎tests/SharpCoreDB.Tests/Storage/CompressionLevelTests.cs‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,10 @@ public void BlockCompressor_GZip_HigherEffortDoesNotIncreaseSize()
9393
$"SmallestSize ({smallest.Length}) should be smaller than raw ({data.Length})");
9494
}
9595

96-
/// <summary>
97-
/// Skips Zstd-only tests until a .NET runtime ships a native Zstandard stream
98-
/// (verified: .NET 11 RC1's System.IO.Compression has no ZstandardStream yet).
99-
/// No-op on runtimes without Zstandard support; the covered tests are net11-gated anyway.
100-
/// </summary>
101-
private static void SkipIfZstdUnsupported()
102-
{
103-
#if NET11_0_OR_GREATER
104-
Assert.Skip("Zstandard compression is not available in the current .NET runtime (System.IO.Compression has no ZstandardStream yet).");
105-
#endif
106-
}
107-
108-
private static void SkipIfZstd(BlockCompressionMode mode)
109-
{
110-
#if NET11_0_OR_GREATER
111-
if (mode == BlockCompressionMode.Zstd)
112-
{
113-
SkipIfZstdUnsupported();
114-
}
115-
#endif
116-
}
117-
11896
#if NET11_0_OR_GREATER
11997
[Fact]
12098
public void BlockCompressor_Zstd_HigherEffortDoesNotIncreaseSize()
12199
{
122-
SkipIfZstdUnsupported();
123-
124100
var data = RealisticCompressiblePayload();
125101

126102
var fastest = BlockCompressor.Compress(data, BlockCompressionMode.Zstd, OptionalCompressionLevel.Fastest);
@@ -141,8 +117,6 @@ public void BlockCompressor_Zstd_HigherEffortDoesNotIncreaseSize()
141117
[InlineData(OptionalCompressionLevel.SmallestSize)]
142118
public void BlockCompressor_Zstd_Roundtrip_PreservesData(OptionalCompressionLevel level)
143119
{
144-
SkipIfZstdUnsupported();
145-
146120
var data = RealisticCompressiblePayload();
147121

148122
var compressed = BlockCompressor.Compress(data, BlockCompressionMode.Zstd, level);
@@ -315,8 +289,6 @@ private static string GenerateRealisticMetadata(int tableCount)
315289
#endif
316290
public void GetReadStream_CompressedBlock_NoEncryption_ReturnsDecompressedData(BlockCompressionMode mode)
317291
{
318-
SkipIfZstd(mode);
319-
320292
var path = Path.Combine(Path.GetTempPath(), $"readstream_{mode}_{Guid.NewGuid():N}.scdb");
321293
var originalData = RealisticCompressiblePayload();
322294

@@ -366,8 +338,6 @@ public void GetReadStream_CompressedBlock_NoEncryption_ReturnsDecompressedData(B
366338
#endif
367339
public void GetReadSpan_CompressedBlock_NoEncryption_ReturnsDecompressedData(BlockCompressionMode mode)
368340
{
369-
SkipIfZstd(mode);
370-
371341
var path = Path.Combine(Path.GetTempPath(), $"readspan_{mode}_{Guid.NewGuid():N}.scdb");
372342
var originalData = RealisticCompressiblePayload();
373343

0 commit comments

Comments
 (0)