Skip to content

Commit 6f1889d

Browse files
committed
Changes.
1 parent 84f68cd commit 6f1889d

13 files changed

Lines changed: 96 additions & 109 deletions

src/ZlibSharp.Native/Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
<WholeProgramOptimization Condition="'$(Configuration)' == 'Release'">true</WholeProgramOptimization>
3636
<CharacterSet>Unicode</CharacterSet>
3737
<IntDir>obj\$(Configuration)\$(Platform)\</IntDir>
38-
<OutDir Condition="'$(Platform)' == 'Win32'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-x86\</OutDir>
39-
<OutDir Condition="'$(Platform)' == 'x64'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-x64\</OutDir>
40-
<OutDir Condition="'$(Platform)' == 'ARM64'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-arm64\</OutDir>
38+
<OutDir Condition="'$(Platform)' == 'Win32'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-x86\native\</OutDir>
39+
<OutDir Condition="'$(Platform)' == 'x64'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-x64\native\</OutDir>
40+
<OutDir Condition="'$(Platform)' == 'ARM64'">..\ZlibSharp\bin\$(Configuration)\net10.0\runtimes\win-arm64\native\</OutDir>
4141
</PropertyGroup>
4242

4343
<ImportGroup Label="PropertySheets">

src/ZlibSharp/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Using Include="System.Runtime.Serialization" />
77
<Using Include="System.Runtime.CompilerServices" />
88
<Using Include="System.Text" />
9+
<None Include="bin\$(Configuration)\$(TargetFramework)\runtimes\**\*.*" Pack="true" CopyToOutputDirectory="PreserveNewest" />
910
</ItemGroup>
1011

1112
</Project>

src/ZlibSharp/ZlibSharp/Extensions/ZlibDecoderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public static class ZlibDecoderExtensions
1717
/// </summary>
1818
/// <param name="decoder">The <see cref="ZlibDecoder" /> instance to use.</param>
1919
/// <param name="source">The compressed input data.</param>
20-
/// <exception cref="NotUnpackableException">
21-
/// Thrown when zlib errors internally in any way.
22-
/// </exception>
2320
/// <returns>The size of the data when it is decompressed.</returns>
2421
public static uint GetDecompressedSize(this ZlibDecoder decoder, ReadOnlySpan<byte> source)
2522
{

src/ZlibSharp/ZlibSharp/Extensions/ZlibEncoderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public static class ZlibEncoderExtensions
1717
/// </summary>
1818
/// <param name="encoder">The <see cref="ZlibEncoder" /> instance to use.</param>
1919
/// <param name="source">The input data buffer.</param>
20-
/// <exception cref="NotPackableException">
21-
/// Thrown when zlib errors internally in any way.
22-
/// </exception>
2320
/// <returns>The size of the data when it is compressed.</returns>
2421
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2522
public static uint GetCompressedSize(this ZlibEncoder encoder, ReadOnlySpan<byte> source)

src/ZlibSharp/ZlibSharp/Internal/Crc32Hash.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace ZlibSharp.Internal;
1010
internal struct Crc32Hash : ICompressionHash
1111
{
1212
// <inheritdoc/>
13-
public readonly uint ComputeHash(ReadOnlySpan<byte> source)
14-
=> unchecked((uint)(ZlibHelper.GetCrc32(source) & 0xFFFFFFFF));
13+
public unsafe readonly uint ComputeHash(ReadOnlySpan<byte> source)
14+
{
15+
fixed (byte* sourcePtr = source)
16+
{
17+
return unchecked((uint)(UnsafeNativeMethods.Crc32_ComputeHash(sourcePtr) & 0xFFFFFFFF));
18+
}
19+
}
1520
}

src/ZlibSharp/ZlibSharp/Internal/UnsafeNativeMethods.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,29 @@ internal static unsafe partial class UnsafeNativeMethods
5353
// [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
5454
// internal static partial ulong crc32(ulong crc, byte* buf, uint len);
5555

56+
// private const DllImportSearchPath searchPaths
57+
// = DllImportSearchPath.UseDllDirectoryForDependencies
58+
// | DllImportSearchPath.ApplicationDirectory
59+
// | DllImportSearchPath.System32
60+
// | DllImportSearchPath.UserDirectories;
61+
5662
[DefaultDllImportSearchPaths(DllImportSearchPath.LegacyBehavior)]
57-
[LibraryImport("zlib", EntryPoint = "Compress")]
58-
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
63+
[LibraryImport(ZlibHelper.ZlibLibFileName, EntryPoint = "Compress")]
64+
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
5965
internal static partial uint Compress(CompressDecompressArgs* args);
6066

6167
[DefaultDllImportSearchPaths(DllImportSearchPath.LegacyBehavior)]
62-
[LibraryImport("zlib", EntryPoint = "Decompress")]
63-
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
68+
[LibraryImport(ZlibHelper.ZlibLibFileName, EntryPoint = "Compress")]
69+
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
6470
internal static partial uint Decompress(CompressDecompressArgs* args);
6571

6672
[DefaultDllImportSearchPaths(DllImportSearchPath.LegacyBehavior)]
67-
[LibraryImport("zlib", EntryPoint = "Crc32_ComputeHash")]
68-
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
73+
[LibraryImport(ZlibHelper.ZlibLibFileName, EntryPoint = "Compress")]
74+
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
6975
internal static partial ulong Crc32_ComputeHash(byte* source);
7076

7177
[DefaultDllImportSearchPaths(DllImportSearchPath.LegacyBehavior)]
72-
[LibraryImport("zlib", EntryPoint = "Adler32_ComputeHash")]
73-
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
78+
[LibraryImport(ZlibHelper.ZlibLibFileName, EntryPoint = "Compress")]
79+
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
7480
internal static partial ulong Adler32_ComputeHash(byte* source);
7581
}

src/ZlibSharp/ZlibSharp/Internal/ZStream.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace ZlibSharp.Internal;
77

8+
/*
89
[ExcludeFromCodeCoverage]
910
[StructLayout(LayoutKind.Sequential)]
1011
internal unsafe struct ZStream
@@ -28,3 +29,4 @@ internal unsafe struct ZStream
2829
internal CULong adler;
2930
internal CULong reserved; // reserved for future use in zlib.
3031
}
32+
*/

src/ZlibSharp/ZlibSharp/Internal/ZlibFlushMethod.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace ZlibSharp.Internal;
77

8+
/*
89
internal enum ZlibFlushStrategy
910
{
1011
NoFlush,
@@ -15,3 +16,4 @@ internal enum ZlibFlushStrategy
1516
Block,
1617
Trees,
1718
}
19+
*/

src/ZlibSharp/ZlibSharp/Internal/ZlibHelper.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55

66
namespace ZlibSharp.Internal;
77

8-
using ZlibSharp.Exceptions;
9-
108
[ExcludeFromCodeCoverage]
119
internal static unsafe class ZlibHelper
1210
{
1311
private static bool zlibResolverAdded;
1412

15-
internal static string ZlibLibFileName
16-
=> (OperatingSystem.IsWindows(), OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD() || OperatingSystem.IsAndroid(), OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst(), OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) switch
17-
{
18-
(true, false, false, false) => "ZlibSharp.Native.dll",
19-
(false, true, false, false) => "libZlibSharp.Native.so",
20-
(false, false, true, false) => "libZlibSharp.Native.dylib",
21-
(false, false, false, true) => "__Internal",
22-
_ => throw new PlatformNotSupportedException("Zlib is probably not supported on this platform."),
23-
};
13+
// internal static string ZlibLibFileName
14+
// => (OperatingSystem.IsWindows(), OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD() || OperatingSystem.IsAndroid(), OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst(), OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) switch
15+
// {
16+
// (true, false, false, false) => "ZlibSharp.Native.dll",
17+
// (false, true, false, false) => "libZlibSharp.Native.so",
18+
// (false, false, true, false) => "libZlibSharp.Native.dylib",
19+
// (false, false, false, true) => "__Internal",
20+
// _ => throw new PlatformNotSupportedException("Zlib is probably not supported on this platform."),
21+
// };
22+
#if !TARGET_IOS
23+
internal const string ZlibLibFileName = "ZlibSharp.Native";
24+
#else
25+
internal const string ZlibLibFileName = "__Internal";
26+
#endif
2427

2528
internal static uint Compress(ReadOnlySpan<byte> source, Span<byte> dest, ZlibCompressionLevel compressionLevel, ZlibWindowBits windowBits, ZlibCompressionStrategy strategy, out ZlibStatus status)
2629
{
@@ -122,18 +125,17 @@ internal static uint Decompress(ReadOnlySpan<byte> source, Span<byte> dest, out
122125
// }
123126
// }
124127

125-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
126-
internal static ulong GetCrc32(ReadOnlySpan<byte> data)
127-
{
128-
fixed (byte* dataPtr = data)
129-
{
130-
return UnsafeNativeMethods.Crc32_ComputeHash(dataPtr);
131-
// return UnsafeNativeMethods.crc32(
132-
// UnsafeNativeMethods.crc32(0L, null, 0),
133-
// dataPtr,
134-
// (uint)data.Length);
135-
}
136-
}
128+
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
129+
// internal static ulong GetCrc32(ReadOnlySpan<byte> data)
130+
// {
131+
// fixed (byte* dataPtr = data)
132+
// {
133+
// return UnsafeNativeMethods.crc32(
134+
// UnsafeNativeMethods.crc32(0L, null, 0),
135+
// dataPtr,
136+
// (uint)data.Length);
137+
// }
138+
// }
137139

138140
private static void PreOperationCheck()
139141
{

src/ZlibSharp/ZlibSharp/Internal/internal_state.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
namespace ZlibSharp.Internal;
77

8+
/*
89
[ExcludeFromCodeCoverage]
910
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Used internally by the native zlib library.")]
1011
internal struct internal_state
1112
{
1213
}
14+
*/

0 commit comments

Comments
 (0)