System.IO.Compression.DecodeHelper.UpdateCrc32 C# (CSharp) Méthode

UpdateCrc32() public static méthode

public static UpdateCrc32 ( uint crc32, byte buffer, int offset, int length ) : uint
crc32 uint
buffer byte
offset int
length int
Résultat uint
        public static uint UpdateCrc32(uint crc32, byte[] buffer, int offset, int length) {
            crc32 ^= uint.MaxValue;
            while (--length >= 0) {
                crc32 = crcTable[((crc32 ^ buffer[offset++]) & 0xff)] ^ (crc32 >> 8);
            }
            crc32 ^= uint.MaxValue;
            return crc32;
        }
    }

Usage Example

Exemple #1
0
        public int Inflate(byte[] bytes, int offset, int length)
        {
            // copy bytes from output to outputbytes if we have aviable bytes
            // if buffer is not filled up. keep decoding until no input are available
            // if decodeBlock returns false. Throw an exception.
            int count = 0;

            do
            {
                int copied = output.CopyTo(bytes, offset, length);
                if (copied > 0)
                {
                    if (using_gzip)
                    {
                        crc32 = DecodeHelper.UpdateCrc32(crc32, bytes, offset, copied);
                        uint n = streamSize + (uint)copied;
                        if (n < streamSize)    // overflow, the gzip stream is probably malicious.
                        {
                            throw new InvalidDataException(SR.GetString(SR.StreamSizeOverflow));
                        }
                        streamSize = n;
                    }

                    offset += copied;
                    count  += copied;
                    length -= copied;
                }

                if (length == 0)     // filled in the bytes array
                {
                    break;
                }
                // Decode will return false when more input is needed
            } while (!Finished() && Decode());

            if (state == InflaterState.VerifyingGZIPFooter)    // finished reading CRC
            // In this case finished is true and output window has all the data.
            // But some data in output window might not be copied out.
            {
                if (output.AvailableBytes == 0)
                {
                    if (crc32 != gZipDecoder.Crc32)
                    {
                        throw new InvalidDataException(SR.GetString(SR.InvalidCRC));
                    }

                    if (streamSize != gZipDecoder.StreamSize)
                    {
                        throw new InvalidDataException(SR.GetString(SR.InvalidStreamSize));
                    }
                }
            }

            return(count);
        }
All Usage Examples Of System.IO.Compression.DecodeHelper::UpdateCrc32