Ionic.Crc.CRC32.SlurpBlock C# (CSharp) Method

SlurpBlock() public method

Update the value for the running CRC32 using the given block of bytes. This is useful when using the CRC32() class in a Stream.
public SlurpBlock ( byte block, int offset, int count ) : void
block byte block of bytes to slurp
offset int starting point in the block
count int how many bytes within the block to slurp
return void
        public void SlurpBlock(byte[] block, int offset, int count)
        {
            if (block == null)
                throw new Exception("The data buffer must not be null.");

            // bzip algorithm
            for (int i = 0; i < count; i++)
            {
                int x = offset + i;
                byte b = block[x];
                if (this.reverseBits)
                {
                    UInt32 temp = (_register >> 24) ^ b;
                    _register = (_register << 8) ^ crc32Table[temp];
                }
                else
                {
                    UInt32 temp = (_register & 0x000000FF) ^ b;
                    _register = (_register >> 8) ^ crc32Table[temp];
                }
            }
            _TotalBytesRead += count;
        }

Usage Example

コード例 #1
0
ファイル: CRC32.cs プロジェクト: craig-b/Zlib.Portable
        /// <summary>
        /// Read from the stream
        /// </summary>
        /// <param name="buffer">the buffer to read</param>
        /// <param name="offset">the offset at which to start</param>
        /// <param name="count">the number of bytes to read</param>
        /// <returns>the number of bytes actually read</returns>
        public override int Read(byte[] buffer, int offset, int count)
        {
            int bytesToRead = count;

            // Need to limit the # of bytes returned, if the stream is intended to have
            // a definite length.  This is especially useful when returning a stream for
            // the uncompressed data directly to the application.  The app won't
            // necessarily read only the UncompressedSize number of bytes.  For example
            // wrapping the stream returned from OpenReader() into a StreadReader() and
            // calling ReadToEnd() on it, We can "over-read" the zip data and get a
            // corrupt string.  The length limits that, prevents that problem.

            if (_lengthLimit != UnsetLengthLimit)
            {
                if (_Crc32.TotalBytesRead >= _lengthLimit)
                {
                    return(0);                                       // EOF
                }
                var bytesRemaining = _lengthLimit - _Crc32.TotalBytesRead;
                if (bytesRemaining < count)
                {
                    bytesToRead = (int)bytesRemaining;
                }
            }
            int n = _innerStream.Read(buffer, offset, bytesToRead);

            if (n > 0)
            {
                _Crc32.SlurpBlock(buffer, offset, n);
            }
            return(n);
        }
All Usage Examples Of Ionic.Crc.CRC32::SlurpBlock