This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 54fd56c  Removed support for DotNetZip for ZLIB compression
54fd56c is described below

commit 54fd56c6f09151a28ae974a74ecaae494fc413fe
Author: Daniel Blankensteiner <[email protected]>
AuthorDate: Wed Dec 11 11:55:11 2024 +0100

    Removed support for DotNetZip for ZLIB compression
---
 CHANGELOG.md                                       |   4 +
 benchmarks/Compression/Compress.cs                 |   7 --
 benchmarks/Compression/Compression.csproj          |   1 -
 benchmarks/Compression/Decompress.cs               |  10 --
 benchmarks/Compression/Factories.cs                |   8 --
 benchmarks/Compression/Program.cs                  |   2 -
 .../Internal/Compression/CompressionFactories.cs   |   2 -
 .../Internal/Compression/ZlibCompression.cs        | 124 ---------------------
 tests/DotPulsar.Tests/DotPulsar.Tests.csproj       |   1 -
 .../Internal/Compression/ZlibCompressionTests.cs   |  37 ------
 10 files changed, 4 insertions(+), 192 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 787d041..ab9a2cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@ The format is based on [Keep a 
Changelog](https://keepachangelog.com/en/1.1.0/)
 
 - **Breaking**: The consumer, reader, and producer now implements IStateHolder 
instead of IState
 
+### Removed
+
+- Support for DotNetZip for ZLIB compression
+
 ## [3.6.0] - 2024-12-09
 
 ### Added
diff --git a/benchmarks/Compression/Compress.cs 
b/benchmarks/Compression/Compress.cs
index 994de36..1dbac5b 100644
--- a/benchmarks/Compression/Compress.cs
+++ b/benchmarks/Compression/Compress.cs
@@ -53,13 +53,6 @@ public class Compress
         _ = compressor.Compress(Data);
     }
 
-    [Benchmark]
-    public void DotNetZip()
-    {
-        using var compressor = Factories.DotNetZipCompressorFactory.Create();
-        _ = compressor.Compress(Data);
-    }
-
     [Benchmark]
     public void ZstdNet()
     {
diff --git a/benchmarks/Compression/Compression.csproj 
b/benchmarks/Compression/Compression.csproj
index 7e53a1f..d25c162 100644
--- a/benchmarks/Compression/Compression.csproj
+++ b/benchmarks/Compression/Compression.csproj
@@ -9,7 +9,6 @@
 
   <ItemGroup>
     <PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
-    <PackageReference Include="DotNetZip" Version="1.16.0" />
     <PackageReference Include="Google.Protobuf" Version="3.29.0" />
     <PackageReference Include="Grpc.Tools" Version="2.68.1">
       <PrivateAssets>all</PrivateAssets>
diff --git a/benchmarks/Compression/Decompress.cs 
b/benchmarks/Compression/Decompress.cs
index 2980705..5561574 100644
--- a/benchmarks/Compression/Decompress.cs
+++ b/benchmarks/Compression/Decompress.cs
@@ -39,8 +39,6 @@ public class Decompress
             IronSnappyData = compressor.Compress(data);
         using (var compressor = 
Factories.BuiltinZlibCompressionCompressorFactory.Create())
             BuiltinZlibData = compressor.Compress(data);
-        using (var compressor = Factories.DotNetZipCompressorFactory.Create())
-            DotNetZipData = compressor.Compress(data);
         using (var compressor = Factories.ZstdNetCompressorFactory.Create())
             ZstdNetData = compressor.Compress(data);
         using (var compressor = Factories.ZstdSharpCompressorFactory.Create())
@@ -51,7 +49,6 @@ public class Decompress
     public ReadOnlySequence<byte> K4aosCompressionLz4Data { get; private set; }
     public ReadOnlySequence<byte> IronSnappyData { get; private set; }
     public ReadOnlySequence<byte> BuiltinZlibData { get; private set; }
-    public ReadOnlySequence<byte> DotNetZipData { get; private set; }
     public ReadOnlySequence<byte> ZstdNetData { get; private set; }
     public ReadOnlySequence<byte> ZstdSharpData { get; private set; }
 
@@ -76,13 +73,6 @@ public class Decompress
         _ = decompressor.Decompress(BuiltinZlibData, DecompressedSize);
     }
 
-    [Benchmark]
-    public void DotNetZip()
-    {
-        using var decompressor = 
Factories.DotNetZipDecompressorFactory.Create();
-        _ = decompressor.Decompress(DotNetZipData, DecompressedSize);
-    }
-
     [Benchmark]
     public void ZstdNet()
     {
diff --git a/benchmarks/Compression/Factories.cs 
b/benchmarks/Compression/Factories.cs
index 7de2a2f..e1da690 100644
--- a/benchmarks/Compression/Factories.cs
+++ b/benchmarks/Compression/Factories.cs
@@ -36,11 +36,6 @@ public static class Factories
         BuiltinZlibCompressionCompressorFactory = compressor!;
         BuiltinZlibCompressionDecompressorFactory = decompressor!;
 
-        if (!ZlibCompression.TryLoading(out compressor, out decompressor))
-            throw new Exception("Could not load DotNetZip");
-        DotNetZipCompressorFactory = compressor!;
-        DotNetZipDecompressorFactory = decompressor!;
-
         if (!ZstdCompression.TryLoading(out compressor, out decompressor))
             throw new Exception("Could not load ZstdNet");
         ZstdNetCompressorFactory = compressor!;
@@ -61,9 +56,6 @@ public static class Factories
     public static ICompressorFactory BuiltinZlibCompressionCompressorFactory { 
get; }
     public static IDecompressorFactory 
BuiltinZlibCompressionDecompressorFactory { get; }
 
-    public static ICompressorFactory DotNetZipCompressorFactory { get; }
-    public static IDecompressorFactory DotNetZipDecompressorFactory { get; }
-
     public static ICompressorFactory ZstdNetCompressorFactory { get; }
     public static IDecompressorFactory ZstdNetDecompressorFactory { get; }
 
diff --git a/benchmarks/Compression/Program.cs 
b/benchmarks/Compression/Program.cs
index 6f0aa4e..bbdac75 100644
--- a/benchmarks/Compression/Program.cs
+++ b/benchmarks/Compression/Program.cs
@@ -31,8 +31,6 @@ static void OutputCompressionInfo(MessageSize size, 
MessageType type)
         Console.WriteLine($"\tCompressed with K4os.Compression.LZ4: 
{compressor.Compress(data).Length}");
     using (var compressor = Factories.IronSnappyCompressorFactory.Create())
         Console.WriteLine($"\tCompressed with IronSnappy: 
{compressor.Compress(data).Length}");
-    using (var compressor = Factories.DotNetZipCompressorFactory.Create())
-        Console.WriteLine($"\tCompressed with DotNetZip: 
{compressor.Compress(data).Length}");
     using (var compressor = 
Factories.BuiltinZlibCompressionCompressorFactory.Create())
         Console.WriteLine($"\tCompressed with System.IO.Compression: 
{compressor.Compress(data).Length}");
     using (var compressor = Factories.ZstdNetCompressorFactory.Create())
diff --git a/src/DotPulsar/Internal/Compression/CompressionFactories.cs 
b/src/DotPulsar/Internal/Compression/CompressionFactories.cs
index 288d168..ecf87a2 100644
--- a/src/DotPulsar/Internal/Compression/CompressionFactories.cs
+++ b/src/DotPulsar/Internal/Compression/CompressionFactories.cs
@@ -48,8 +48,6 @@ public static class CompressionFactories
     {
         if (BuiltinZlibCompression.TryLoading(out var compressorFactory, out 
var decompressorFactory))
             Add(compressorFactory, decompressorFactory);
-        else if (ZlibCompression.TryLoading(out compressorFactory, out 
decompressorFactory))
-            Add(compressorFactory, decompressorFactory);
     }
 
     private static void LoadSupportForZstd()
diff --git a/src/DotPulsar/Internal/Compression/ZlibCompression.cs 
b/src/DotPulsar/Internal/Compression/ZlibCompression.cs
deleted file mode 100644
index fa6157b..0000000
--- a/src/DotPulsar/Internal/Compression/ZlibCompression.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace DotPulsar.Internal.Compression;
-
-using DotPulsar.Internal.Abstractions;
-using System.Buffers;
-using System.Reflection;
-
-public static class ZlibCompression
-{
-    public delegate byte[] CompressBuffer(byte[] source);
-    public delegate byte[] UncompressBuffer(byte[] source);
-
-    public static bool TryLoading(out ICompressorFactory? compressorFactory, 
out IDecompressorFactory? decompressorFactory)
-    {
-        try
-        {
-            var assembly = Assembly.Load("DotNetZip");
-
-            var definedTypes = assembly.DefinedTypes.ToArray();
-
-            var ZlibStream = FindZlibStream(definedTypes);
-
-            var methods = ZlibStream.GetMethods(BindingFlags.Public | 
BindingFlags.Static);
-
-            var compressBuffer = FindCompressBuffer(methods);
-            var uncompressBuffer = FindUncompressBuffer(methods);
-
-            compressorFactory = new 
CompressorFactory(PulsarApi.CompressionType.Zlib, () => new 
Compressor(CreateCompressor(compressBuffer)));
-            decompressorFactory = new 
DecompressorFactory(PulsarApi.CompressionType.Zlib, () => new 
Decompressor(CreateDecompressor(uncompressBuffer)));
-
-            return CompressionTester.TestCompression(compressorFactory, 
decompressorFactory);
-        }
-        catch
-        {
-            // Ignore
-        }
-
-        compressorFactory = null;
-        decompressorFactory = null;
-
-        return false;
-    }
-
-    private static TypeInfo FindZlibStream(IEnumerable<TypeInfo> types)
-    {
-        const string fullName = "Ionic.Zlib.ZlibStream";
-
-        foreach (var type in types)
-        {
-            if (type.FullName is null || !type.FullName.Equals(fullName))
-                continue;
-
-            if (type.IsPublic && type.IsClass)
-                return type;
-
-            break;
-        }
-
-        throw new Exception($"{fullName} as a public class was not found");
-    }
-
-    private static CompressBuffer FindCompressBuffer(MethodInfo[] methods)
-    {
-        const string name = "CompressBuffer";
-
-        foreach (var method in methods)
-        {
-            if (method.Name != name || method.ReturnType != typeof(byte[]))
-                continue;
-
-            var parameters = method.GetParameters();
-            if (parameters.Length != 1)
-                continue;
-
-            if (parameters[0].ParameterType != typeof(byte[]))
-                continue;
-
-            return (CompressBuffer) 
method.CreateDelegate(typeof(CompressBuffer));
-        }
-
-        throw new Exception($"A method with the name '{name}' matching the 
delegate was not found");
-    }
-
-    private static UncompressBuffer FindUncompressBuffer(MethodInfo[] methods)
-    {
-        const string name = "UncompressBuffer";
-
-        foreach (var method in methods)
-        {
-            if (method.Name != name || method.ReturnType != typeof(byte[]))
-                continue;
-
-            var parameters = method.GetParameters();
-            if (parameters.Length != 1)
-                continue;
-
-            if (parameters[0].ParameterType != typeof(byte[]))
-                continue;
-
-            return (UncompressBuffer) 
method.CreateDelegate(typeof(UncompressBuffer));
-        }
-
-        throw new Exception($"A method with the name '{name}' matching the 
delegate was not found");
-    }
-
-    private static Func<ReadOnlySequence<byte>, int, ReadOnlySequence<byte>> 
CreateDecompressor(UncompressBuffer decompress)
-        => (source, size) => new 
ReadOnlySequence<byte>(decompress(source.ToArray()));
-
-    private static Func<ReadOnlySequence<byte>, ReadOnlySequence<byte>> 
CreateCompressor(CompressBuffer compress)
-        => (source) => new ReadOnlySequence<byte>(compress(source.ToArray()));
-}
diff --git a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj 
b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
index 82327d9..296089e 100644
--- a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
+++ b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
@@ -18,7 +18,6 @@
     <PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
     <PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
     <PackageReference Include="coverlet.collector" Version="6.0.2" />
-    <PackageReference Include="DotNetZip" Version="1.16.0" />
     <PackageReference Include="FluentAssertions" Version="7.0.0" />
     <PackageReference Include="IronSnappy" Version="1.3.1" />
     <PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
diff --git a/tests/DotPulsar.Tests/Internal/Compression/ZlibCompressionTests.cs 
b/tests/DotPulsar.Tests/Internal/Compression/ZlibCompressionTests.cs
deleted file mode 100644
index 3477e2b..0000000
--- a/tests/DotPulsar.Tests/Internal/Compression/ZlibCompressionTests.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace DotPulsar.Tests.Internal.Compression;
-
-using DotPulsar.Internal.Compression;
-
-[Trait("Category", "Unit")]
-public class ZlibCompressionTests
-{
-    [Fact]
-    public void 
Compression_GivenDataToCompressAndDecompress_ShouldReturnOriginalData()
-    {
-        // Arrange
-        var couldLoad = ZlibCompression.TryLoading(out var compressorFactory, 
out var decompressorFactory);
-        couldLoad.Should().BeTrue();
-        using var compressor = compressorFactory!.Create();
-        using var decompressor = decompressorFactory!.Create();
-
-        // Act
-        var compressionWorks = 
CompressionTester.TestCompression(compressorFactory, decompressorFactory);
-
-        // Assert
-        compressionWorks.Should().BeTrue();
-    }
-}

Reply via email to