System.IO.Compression.Crc32.Calculate C# (CSharp) Method

Calculate() static private method

Caclulate the CRC (Cyclic Reduncancy Check) for a buffer of bytes See RFC1952 for details.
static private Calculate ( byte buffer ) : uint
buffer byte The byte buffer.
return uint
        internal static uint Calculate(byte[] buffer)
        {
            return Calculate(buffer, 0, buffer.Length);
        }

Same methods

Crc32::Calculate ( byte buffer, int offset, int length ) : uint
Crc32::Calculate ( uint crc32, byte buffer, int offset, int length ) : uint

Usage Example

        /// <summary>
        /// Validate the data.
        /// </summary>
        internal void Validate()
        {
            Stream readStream = OpenRead();
            uint   crc        = 0;

            byte[] buffer = new byte[655536];
            for (;;)
            {
                int count = readStream.Read(buffer, 0, buffer.Length);
                if (count == 0)
                {
                    break;
                }
                crc = Crc32.Calculate(crc, buffer, 0, count);
            }

            readStream.Close();

            if (crc != CheckSum)
            {
                throw new InvalidOperationException("Error: data checksum failed for " + Name);
            }
        }