| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Runtime.InteropServices; |
| | | 6 | | |
| | | 7 | | namespace System.IO.Compression |
| | | 8 | | { |
| | | 9 | | internal static class Crc32Helper |
| | | 10 | | { |
| | | 11 | | // Calculate CRC based on the old CRC and the new bytes |
| | | 12 | | public static unsafe uint UpdateCrc32(uint crc32, byte[] buffer, int offset, int length) |
| | 0 | 13 | | { |
| | 0 | 14 | | Debug.Assert((buffer != null) && (offset >= 0) && (length >= 0) && (offset <= buffer.Length - length)); |
| | 0 | 15 | | fixed (byte* bufferPtr = &buffer[offset]) |
| | 0 | 16 | | { |
| | 0 | 17 | | return Interop.ZLib.crc32(crc32, bufferPtr, length); |
| | | 18 | | } |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | public static unsafe uint UpdateCrc32(uint crc32, ReadOnlySpan<byte> buffer) |
| | 0 | 22 | | { |
| | 0 | 23 | | fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) |
| | 0 | 24 | | { |
| | 0 | 25 | | return Interop.ZLib.crc32(crc32, bufferPtr, buffer.Length); |
| | | 26 | | } |
| | 0 | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |