Moves zlib to its own nuget (#164)

This commit is contained in:
Kamron Batman 2020-06-25 13:48:40 -07:00 committed by GitHub
parent 561b40c3d8
commit d76d60d900
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 75 additions and 398 deletions

View file

@ -1181,10 +1181,10 @@
"xunit.extensibility.core": "[2.4.1]"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"ModernUO": {
"type": "Project",
@ -1193,7 +1193,7 @@
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv": "3.1.5",
"Microsoft.Extensions.Hosting.Abstractions": "3.1.5",
"System.IO.Pipelines": "4.7.2",
"ZLib.Bindings": "1.0.2"
"Zlib.Bindings": "1.0.3"
}
}
},
@ -2065,10 +2065,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
},
".NETCoreApp,Version=v3.1/osx-x64": {
@ -2939,10 +2939,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
},
".NETCoreApp,Version=v3.1/win-x64": {
@ -3796,10 +3796,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
}
}

View file

@ -22,7 +22,7 @@ using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using Server.Compression;
using System.IO.Compression;
namespace Server
{
@ -167,7 +167,7 @@ namespace Server
if (compressionMethod == 1)
{
data = new byte[decompressedSize];
ZLib.Unpack(data, ref decompressedSize, sourceData, compressedSize);
Zlib.Unpack(data, ref decompressedSize, sourceData, compressedSize);
}
else
{

View file

@ -21,8 +21,8 @@
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using Server.Compression;
using Server.Gumps;
namespace Server.Network
@ -183,7 +183,7 @@ namespace Server.Network
var packLength = wantLength;
ZLib.Pack(packBuffer, ref packLength, buffer, length, ZLibQuality.Default);
Zlib.Pack(packBuffer, ref packLength, buffer, length, ZlibQuality.Default);
Stream.Write(4 + packLength);
Stream.Write(length);

View file

@ -69,7 +69,7 @@
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.5" />
<PackageReference Include="System.IO.Pipelines" Version="4.7.2" />
<PackageReference Include="ZLib.Bindings" Version="1.0.2" />
<PackageReference Include="Zlib.Bindings" Version="1.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Analyze'">
<PackageReference Include="StyleCop.Analyzers">

View file

@ -42,11 +42,11 @@
"resolved": "4.7.2",
"contentHash": "rGIIhoY3lUdn9rWeuGdgeZZ0P+SpJ1wZI5g8TnXqgvuhFgUP7iP9Nt5FZebYInQZQxqnwjPxdYYBE5l/8PJmqQ=="
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -112,11 +112,11 @@
}
},
".NETCoreApp,Version=v3.1/linux-x64": {
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -128,11 +128,11 @@
}
},
".NETCoreApp,Version=v3.1/osx-x64": {
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -144,11 +144,11 @@
}
},
".NETCoreApp,Version=v3.1/win-x64": {
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",

View file

@ -1327,10 +1327,10 @@
"xunit.extensibility.core": "[2.4.1]"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"ModernUO": {
"type": "Project",
@ -1339,7 +1339,7 @@
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv": "3.1.5",
"Microsoft.Extensions.Hosting.Abstractions": "3.1.5",
"System.IO.Pipelines": "4.7.2",
"ZLib.Bindings": "1.0.2"
"Zlib.Bindings": "1.0.3"
}
},
"uocontent": {
@ -1351,7 +1351,7 @@
"Microsoft.Extensions.DependencyInjection.Abstractions": "3.1.5",
"Microsoft.Extensions.Hosting.Abstractions": "3.1.5",
"Microsoft.Extensions.Logging.Abstractions": "3.1.5",
"Zlib.Bindings": "1.0.2"
"Zlib.Bindings": "1.0.3"
}
}
},
@ -2239,10 +2239,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
},
".NETCoreApp,Version=v3.1/osx-x64": {
@ -3129,10 +3129,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
},
".NETCoreApp,Version=v3.1/win-x64": {
@ -4016,10 +4016,10 @@
"runtime.any.System.Threading.Timer": "4.3.0"
}
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
}
}
}

View file

@ -3,6 +3,7 @@ using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using Server.Gumps;
@ -10,7 +11,6 @@ using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Compression;
namespace Server.Multis
{
@ -2325,10 +2325,10 @@ namespace Server.Multis
byte[] inflatedBuffer = m_PlaneBuffers[i];
int deflatedLength = m_DeflatedBuffer.Length;
ZLibError ce = ZLib.Pack(m_DeflatedBuffer, ref deflatedLength, inflatedBuffer, size,
ZLibQuality.Default);
ZlibError ce = Zlib.Pack(m_DeflatedBuffer, ref deflatedLength, inflatedBuffer, size,
ZlibQuality.Default);
if (ce != ZLibError.Okay)
if (ce != ZlibError.Okay)
{
Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
deflatedLength = 0;
@ -2361,10 +2361,10 @@ namespace Server.Multis
byte[] inflatedBuffer = m_StairBuffers[i];
int deflatedLength = m_DeflatedBuffer.Length;
ZLibError ce = ZLib.Pack(m_DeflatedBuffer, ref deflatedLength, inflatedBuffer, size,
ZLibQuality.Default);
ZlibError ce = Zlib.Pack(m_DeflatedBuffer, ref deflatedLength, inflatedBuffer, size,
ZlibQuality.Default);
if (ce != ZLibError.Okay)
if (ce != ZlibError.Okay)
{
Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
deflatedLength = 0;

View file

@ -68,7 +68,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
<!-- Direct packages -->
<PackageReference Include="MailKit" Version="2.7.0" />
<PackageReference Include="Zlib.Bindings" Version="1.0.2" />
<PackageReference Include="Zlib.Bindings" Version="1.0.3" />
<PackageReference Include="Argon2.Bindings" Version="1.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Analyze'">

View file

@ -54,11 +54,11 @@
"resolved": "3.1.5",
"contentHash": "ZvwowjRSWXewdPI+whPFXgwF4Qme6Q9KV9SCPEITSGiqHLArct7q5hTBtTzj3GPsVLjTqehvTg6Bd/EQk9JS0A=="
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -792,7 +792,7 @@
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv": "3.1.5",
"Microsoft.Extensions.Hosting.Abstractions": "3.1.5",
"System.IO.Pipelines": "4.7.2",
"ZLib.Bindings": "1.0.2"
"Zlib.Bindings": "1.0.3"
}
}
},
@ -803,11 +803,11 @@
"resolved": "1.3.0",
"contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ=="
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -1506,11 +1506,11 @@
"resolved": "1.3.0",
"contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ=="
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",
@ -2209,11 +2209,11 @@
"resolved": "1.3.0",
"contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ=="
},
"ZLib.Bindings": {
"Zlib.Bindings": {
"type": "Direct",
"requested": "[1.0.2, )",
"resolved": "1.0.2",
"contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg=="
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "zk4N0anMKT8s25NY2Euw+Z5mwlSoh2D1XyYik0NJ2fRrSw96hP7nnu9ii2BRdl0ttdl0oflNZ9cme99JoSavyQ=="
},
"Libuv": {
"type": "Transitive",

View file

@ -1,13 +0,0 @@
using System.Runtime.InteropServices;
namespace Server
{
internal static class RuntimeUtility
{
internal static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
internal static readonly bool IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
internal static readonly bool IsFreeBSD = RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD);
internal static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || IsFreeBSD;
internal static readonly bool IsUnix = IsDarwin || IsFreeBSD || IsLinux;
}
}

View file

@ -1,208 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Server.Compression
{
public static class ZLib
{
public static readonly ICompressor Compressor;
static ZLib()
{
if (RuntimeUtility.IsUnix)
Compressor = new UnixCompressor();
else
Compressor = new Compressor();
}
public static int MaxPackSize(int sourceLength) => (int)Compressor.CompressBound((ulong)sourceLength);
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength)
{
var destLengthLong = (ulong)destLength;
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
(ulong)sourceLength);
destLength = (int)destLengthLong;
return e;
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, ZLibQuality quality)
{
var destLengthLong = (ulong)destLength;
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
(ulong)source.Length, quality);
destLength = (int)destLengthLong;
return e;
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength,
ZLibQuality quality)
{
var destLengthLong = (ulong)destLength;
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
(ulong)sourceLength, quality);
destLength = (int)destLengthLong;
return e;
}
}
public static unsafe ZLibError Unpack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength)
{
var destLengthLong = (ulong)destLength;
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
var e = Compressor.Decompress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
(ulong)sourceLength);
destLength = (int)destLengthLong;
return e;
}
}
public static ulong MaxPackSize(ulong sourceLength) => Compressor.CompressBound(sourceLength);
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength)
{
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength);
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source,
ZLibQuality quality)
{
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), (ulong)source.Length,
quality);
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength,
ZLibQuality quality)
{
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength, quality);
}
}
public static unsafe ZLibError Unpack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source,
ulong sourceLength)
{
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
{
return Compressor.Decompress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength);
}
}
}
public interface ICompressor
{
string Version { get; }
ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength, ZLibQuality quality);
ZLibError Decompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
ulong CompressBound(ulong sourceLength);
}
public class Compressor : ICompressor
{
public string Version => SafeNativeMethods.zlibVersion();
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality) => SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
public ZLibError Decompress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
public ulong CompressBound(ulong sourceLength) => SafeNativeMethods.compressBound(sourceLength);
private static class SafeNativeMethods
{
[DllImport("zlib", CharSet = CharSet.Unicode)]
internal static extern string zlibVersion();
[DllImport("zlib")]
internal static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("zlib")]
internal static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality);
[DllImport("zlib")]
internal static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("zlib")]
internal static extern ulong compressBound(ulong sourceLen);
}
}
public class UnixCompressor : ICompressor
{
public string Version => SafeNativeMethods.zlibVersion();
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality) => SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
public ZLibError Decompress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
public ulong CompressBound(ulong sourceLength) => SafeNativeMethods.compressBound(sourceLength);
internal static class SafeNativeMethods
{
[DllImport("libz", CharSet = CharSet.Unicode)]
internal static extern string zlibVersion();
[DllImport("libz")]
internal static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("libz")]
internal static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality);
[DllImport("libz")]
internal static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("libz")]
internal static extern ulong compressBound(ulong sourceLen);
}
}
public enum ZLibError
{
VersionError = -6,
BufferError = -5,
MemoryError = -4,
DataError = -3,
StreamError = -2,
FileError = -1,
Okay = 0,
StreamEnd = 1,
NeedDictionary = 2
}
public enum ZLibQuality
{
Default = -1,
None = 0,
Speed = 1,
Size = 9
}
}

View file

@ -1,30 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageVersion>1.0.2</PackageVersion>
<RootNamespace>Server</RootNamespace>
<AssemblyName>ZLib.Bindings</AssemblyName>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Configurations>Debug;Release;Analyze</Configurations>
<AssemblyVersion>1.0.2</AssemblyVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Content Include="runtimes\win-x64\native\zlib.dll">
<Pack>true</Pack>
<PackagePath>runtimes/win-x64/native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\osx-x64\native\libz.dylib">
<Pack>true</Pack>
<PackagePath>runtimes/osx-x64/native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\linux-x64\native\libz.so">
<Pack>true</Pack>
<PackagePath>runtimes/linux-x64/native</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View file

@ -1,9 +0,0 @@
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {},
".NETCoreApp,Version=v3.1/linux-x64": {},
".NETCoreApp,Version=v3.1/osx-x64": {},
".NETCoreApp,Version=v3.1/win-x64": {}
}
}