Skip to content

Commit a1a70c2

Browse files
committed
Changes since the initial original repo
+ Update the libzstd library to 1.5.6 - The arm64 library added - Switching from MSVC to Intel C++ Compiler for x86 and x64 library + Adding proper library loading and check for .NET Standard 2.0 and the use of NativeLibrary.SetDllImportResolver() for .NET >= 6.0 compilation. + Code cleanup + Adding compile target to arm64 architecture and platform to .NET >= 6
1 parent 14c8c98 commit a1a70c2

25 files changed

+1249
-1147
lines changed

ZstdNet.Benchmarks/CompressionBenchmarks.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void CompressStream(int zstdBufferSize, int copyBufferSize)
5555
[Arguments(7, 13)]
5656
public async Task CompressStreamAsync(int zstdBufferSize, int copyBufferSize)
5757
{
58-
#if !NET48
58+
#if !NET48_OR_GREATER
5959
await
6060
#endif
6161
using var compressionStream = new CompressionStream(Stream.Null, CompressionOptions.Default, zstdBufferSize);
@@ -74,10 +74,10 @@ public void DecompressStream(int zstdBufferSize, int copyBufferSize)
7474
[Arguments(7, 13)]
7575
public async Task DecompressStreamAsync(int zstdBufferSize, int copyBufferSize)
7676
{
77-
#if !NET48
77+
#if !NET48_OR_GREATER
7878
await
7979
#endif
80-
using var decompressionStream = new DecompressionStream(new MemoryStream(CompressedStreamData), zstdBufferSize);
80+
using var decompressionStream = new DecompressionStream(new MemoryStream(CompressedStreamData), zstdBufferSize);
8181
await decompressionStream.CopyToAsync(Stream.Null, copyBufferSize);
8282
}
8383
}

ZstdNet.Benchmarks/Main.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace ZstdNet.Benchmarks
44
{
5-
class Program
6-
{
7-
static void Main(string[] args)
8-
{
9-
BenchmarkSwitcher
10-
.FromTypes(new[] {typeof(CompressionOverheadBenchmarks)})
11-
.Run(args);
12-
}
13-
}
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
BenchmarkSwitcher
10+
.FromTypes(new[] {typeof(CompressionOverheadBenchmarks)})
11+
.Run(args);
12+
}
13+
}
1414
}

ZstdNet.Benchmarks/ZstdNet.Benchmarks.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>
5+
<TargetFrameworks>net6.0;net7.0;net8.0;net481</TargetFrameworks>
66
<PlatformTarget>AnyCPU</PlatformTarget>
77
<LangVersion>8.0</LangVersion>
88
</PropertyGroup>

ZstdNet.Tests/ZstdNet.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
66
<Platforms>AnyCPU;x64;x86</Platforms>
77
<LangVersion>8.0</LangVersion>

ZstdNet/CompressionOptions.cs

+62-62
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,86 @@
44

55
namespace ZstdNet
66
{
7-
public class CompressionOptions : IDisposable
8-
{
9-
public CompressionOptions(int compressionLevel)
10-
{
11-
if(compressionLevel < MinCompressionLevel || compressionLevel > MaxCompressionLevel)
12-
throw new ArgumentOutOfRangeException(nameof(compressionLevel));
7+
public class CompressionOptions : IDisposable
8+
{
9+
public CompressionOptions(int compressionLevel)
10+
{
11+
if (compressionLevel < MinCompressionLevel || compressionLevel > MaxCompressionLevel)
12+
throw new ArgumentOutOfRangeException(nameof(compressionLevel));
1313

14-
CompressionLevel = compressionLevel;
15-
}
14+
CompressionLevel = compressionLevel;
15+
}
1616

17-
public CompressionOptions(byte[] dict, int compressionLevel = DefaultCompressionLevel)
18-
: this(compressionLevel)
19-
{
20-
Dictionary = dict;
17+
public CompressionOptions(byte[] dict, int compressionLevel = DefaultCompressionLevel)
18+
: this(compressionLevel)
19+
{
20+
Dictionary = dict;
2121

22-
if(dict != null)
23-
Cdict = ExternMethods.ZSTD_createCDict(dict, (size_t)dict.Length, compressionLevel).EnsureZstdSuccess();
24-
else
25-
GC.SuppressFinalize(this); // No unmanaged resources
26-
}
22+
if (dict != null)
23+
Cdict = ExternMethods.ZSTD_createCDict(dict, (size_t)dict.Length, compressionLevel).EnsureZstdSuccess();
24+
else
25+
GC.SuppressFinalize(this); // No unmanaged resources
26+
}
2727

28-
public CompressionOptions(byte[] dict, IReadOnlyDictionary<ZSTD_cParameter, int> advancedParams, int compressionLevel = DefaultCompressionLevel)
29-
: this(dict, compressionLevel)
30-
{
31-
if(advancedParams == null)
32-
return;
28+
public CompressionOptions(byte[] dict, IReadOnlyDictionary<ZSTD_cParameter, int> advancedParams, int compressionLevel = DefaultCompressionLevel)
29+
: this(dict, compressionLevel)
30+
{
31+
if (advancedParams == null)
32+
return;
3333

34-
foreach(var param in advancedParams)
35-
{
36-
var bounds = ExternMethods.ZSTD_cParam_getBounds(param.Key);
37-
bounds.error.EnsureZstdSuccess();
34+
foreach (var param in advancedParams)
35+
{
36+
var bounds = ExternMethods.ZSTD_cParam_getBounds(param.Key);
37+
bounds.error.EnsureZstdSuccess();
3838

39-
if(param.Value < bounds.lowerBound || param.Value > bounds.upperBound)
40-
throw new ArgumentOutOfRangeException(nameof(advancedParams), $"Advanced parameter '{param.Key}' is out of range [{bounds.lowerBound}, {bounds.upperBound}]");
41-
}
39+
if (param.Value < bounds.lowerBound || param.Value > bounds.upperBound)
40+
throw new ArgumentOutOfRangeException(nameof(advancedParams), $"Advanced parameter '{param.Key}' is out of range [{bounds.lowerBound}, {bounds.upperBound}]");
41+
}
4242

43-
this.AdvancedParams = advancedParams;
44-
}
43+
this.AdvancedParams = advancedParams;
44+
}
4545

46-
internal void ApplyCompressionParams(IntPtr cctx)
47-
{
48-
if(AdvancedParams == null || !AdvancedParams.ContainsKey(ZSTD_cParameter.ZSTD_c_compressionLevel))
49-
ExternMethods.ZSTD_CCtx_setParameter(cctx, ZSTD_cParameter.ZSTD_c_compressionLevel, CompressionLevel).EnsureZstdSuccess();
46+
internal void ApplyCompressionParams(IntPtr cctx)
47+
{
48+
if (AdvancedParams == null || !AdvancedParams.ContainsKey(ZSTD_cParameter.ZSTD_c_compressionLevel))
49+
ExternMethods.ZSTD_CCtx_setParameter(cctx, ZSTD_cParameter.ZSTD_c_compressionLevel, CompressionLevel).EnsureZstdSuccess();
5050

51-
if(AdvancedParams == null)
52-
return;
51+
if (AdvancedParams == null)
52+
return;
5353

54-
foreach(var param in AdvancedParams)
55-
ExternMethods.ZSTD_CCtx_setParameter(cctx, param.Key, param.Value).EnsureZstdSuccess();
56-
}
54+
foreach (var param in AdvancedParams)
55+
ExternMethods.ZSTD_CCtx_setParameter(cctx, param.Key, param.Value).EnsureZstdSuccess();
56+
}
5757

58-
~CompressionOptions() => Dispose(false);
58+
~CompressionOptions() => Dispose(false);
5959

60-
public void Dispose()
61-
{
62-
Dispose(true);
63-
GC.SuppressFinalize(this);
64-
}
60+
public void Dispose()
61+
{
62+
Dispose(true);
63+
GC.SuppressFinalize(this);
64+
}
6565

66-
private void Dispose(bool disposing)
67-
{
68-
if(Cdict == IntPtr.Zero)
69-
return;
66+
private void Dispose(bool disposing)
67+
{
68+
if (Cdict == IntPtr.Zero)
69+
return;
7070

71-
ExternMethods.ZSTD_freeCDict(Cdict);
71+
ExternMethods.ZSTD_freeCDict(Cdict);
7272

73-
Cdict = IntPtr.Zero;
74-
}
73+
Cdict = IntPtr.Zero;
74+
}
7575

76-
public static int MinCompressionLevel => ExternMethods.ZSTD_minCLevel();
77-
public static int MaxCompressionLevel => ExternMethods.ZSTD_maxCLevel();
76+
public static int MinCompressionLevel => ExternMethods.ZSTD_minCLevel();
77+
public static int MaxCompressionLevel => ExternMethods.ZSTD_maxCLevel();
7878

79-
public const int DefaultCompressionLevel = 3; // Used by zstd utility by default
79+
public const int DefaultCompressionLevel = 3; // Used by zstd utility by default
8080

81-
public static CompressionOptions Default { get; } = new CompressionOptions(DefaultCompressionLevel);
81+
public static CompressionOptions Default { get; } = new CompressionOptions(DefaultCompressionLevel);
8282

83-
public readonly int CompressionLevel;
84-
public readonly byte[] Dictionary;
85-
public readonly IReadOnlyDictionary<ZSTD_cParameter, int> AdvancedParams;
83+
public readonly int CompressionLevel;
84+
public readonly byte[] Dictionary;
85+
public readonly IReadOnlyDictionary<ZSTD_cParameter, int> AdvancedParams;
8686

87-
internal IntPtr Cdict;
88-
}
87+
internal IntPtr Cdict;
88+
}
8989
}

0 commit comments

Comments
 (0)