C# Class Cimbalino.Phone.Toolkit.Compression.CRC32

Computes a CRC-32. The CRC-32 algorithm is parameterized - you can set the polynomial and enable or disable bit reversal. This can be used for GZIP, BZip2, or ZIP.
This type is used internally by DotNetZip; it is generally not used directly by applications wishing to create, read, or manipulate zip archive files.
Mostra file Open project: Cimbalino/Cimbalino-Phone-Toolkit Class Usage Examples

Public Methods

Method Description
CRC32 ( ) : System

Create an instance of the CRC32 class using the default settings: no bit reversal, and a polynomial of 0xEDB88320.

CRC32 ( bool reverseBits ) : System

Create an instance of the CRC32 class, specifying whether to reverse data bits or not.

In the CRC-32 used by BZip2, the bits are reversed. Therefore if you want a CRC32 with compatibility with BZip2, you should pass true here. In the CRC-32 used by GZIP and PKZIP, the bits are not reversed; Therefore if you want a CRC32 with compatibility with those, you should pass false.

CRC32 ( int polynomial, bool reverseBits ) : System

Create an instance of the CRC32 class, specifying the polynomial and whether to reverse data bits or not.

In the CRC-32 used by BZip2, the bits are reversed. Therefore if you want a CRC32 with compatibility with BZip2, you should pass true here for the reverseBits parameter. In the CRC-32 used by GZIP and PKZIP, the bits are not reversed; Therefore if you want a CRC32 with compatibility with those, you should pass false for the reverseBits parameter.

Combine ( int crc, int length ) : void

Combines the given CRC32 value with the current running total.

This is useful when using a divide-and-conquer approach to calculating a CRC. Multiple threads can each calculate a CRC32 on a segment of the data, and then combine the individual CRC32 values at the end.

ComputeCrc32 ( Int32 W, byte B ) : Int32

Get the CRC32 for the given (word,byte) combo. This is a computation defined by PKzip for PKZIP 2.0 (weak) encryption.

GetCrc32 ( System input ) : Int32

Returns the CRC32 for the specified stream.

GetCrc32AndCopy ( System input, System output ) : Int32

Returns the CRC32 for the specified stream, and writes the input into the output stream.

Reset ( ) : void

Reset the CRC-32 class - clear the CRC "remainder register."

Use this when employing a single instance of this class to compute multiple, distinct CRCs on multiple, distinct data blocks.

SlurpBlock ( byte block, int offset, int count ) : void

Update the value for the running CRC32 using the given block of bytes. This is useful when using the CRC32() class in a Stream.

UpdateCRC ( byte b ) : void

Process one byte in the CRC.

UpdateCRC ( byte b, int n ) : void

Process a run of N identical bytes into the CRC.

This method serves as an optimization for updating the CRC when a run of identical bytes is found. Rather than passing in a buffer of length n, containing all identical bytes b, this method accepts the byte value and the length of the (virtual) buffer - the length of the run.

Private Methods

Method Description
GenerateLookupTable ( ) : void
ReverseBits ( byte data ) : byte
ReverseBits ( uint data ) : uint
_InternalComputeCrc32 ( UInt32 W, byte B ) : Int32
gf2_matrix_square ( uint square, uint mat ) : void
gf2_matrix_times ( uint matrix, uint vec ) : uint

Method Details

CRC32() public method

Create an instance of the CRC32 class using the default settings: no bit reversal, and a polynomial of 0xEDB88320.
public CRC32 ( ) : System
return System

CRC32() public method

Create an instance of the CRC32 class, specifying whether to reverse data bits or not.

In the CRC-32 used by BZip2, the bits are reversed. Therefore if you want a CRC32 with compatibility with BZip2, you should pass true here. In the CRC-32 used by GZIP and PKZIP, the bits are not reversed; Therefore if you want a CRC32 with compatibility with those, you should pass false.

public CRC32 ( bool reverseBits ) : System
reverseBits bool /// specify true if the instance should reverse data bits. ///
return System

CRC32() public method

Create an instance of the CRC32 class, specifying the polynomial and whether to reverse data bits or not.

In the CRC-32 used by BZip2, the bits are reversed. Therefore if you want a CRC32 with compatibility with BZip2, you should pass true here for the reverseBits parameter. In the CRC-32 used by GZIP and PKZIP, the bits are not reversed; Therefore if you want a CRC32 with compatibility with those, you should pass false for the reverseBits parameter.

public CRC32 ( int polynomial, bool reverseBits ) : System
polynomial int /// The polynomial to use for the CRC, expressed in the reversed (LSB) /// format: the highest ordered bit in the polynomial value is the /// coefficient of the 0th power; the second-highest order bit is the /// coefficient of the 1 power, and so on. Expressed this way, the /// polynomial for the CRC-32C used in IEEE 802.3, is 0xEDB88320. ///
reverseBits bool /// specify true if the instance should reverse data bits. ///
return System

Combine() public method

Combines the given CRC32 value with the current running total.
This is useful when using a divide-and-conquer approach to calculating a CRC. Multiple threads can each calculate a CRC32 on a segment of the data, and then combine the individual CRC32 values at the end.
public Combine ( int crc, int length ) : void
crc int the crc value to be combined with this one
length int the length of data the CRC value was calculated on
return void

ComputeCrc32() public method

Get the CRC32 for the given (word,byte) combo. This is a computation defined by PKzip for PKZIP 2.0 (weak) encryption.
public ComputeCrc32 ( Int32 W, byte B ) : Int32
W System.Int32 The word to start with.
B byte The byte to combine it with.
return System.Int32

GetCrc32() public method

Returns the CRC32 for the specified stream.
public GetCrc32 ( System input ) : Int32
input System The stream over which to calculate the CRC32
return System.Int32

GetCrc32AndCopy() public method

Returns the CRC32 for the specified stream, and writes the input into the output stream.
public GetCrc32AndCopy ( System input, System output ) : Int32
input System The stream over which to calculate the CRC32
output System The stream into which to deflate the input
return System.Int32

Reset() public method

Reset the CRC-32 class - clear the CRC "remainder register."

Use this when employing a single instance of this class to compute multiple, distinct CRCs on multiple, distinct data blocks.

public Reset ( ) : void
return void

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

UpdateCRC() public method

Process one byte in the CRC.
public UpdateCRC ( byte b ) : void
b byte the byte to include into the CRC .
return void

UpdateCRC() public method

Process a run of N identical bytes into the CRC.

This method serves as an optimization for updating the CRC when a run of identical bytes is found. Rather than passing in a buffer of length n, containing all identical bytes b, this method accepts the byte value and the length of the (virtual) buffer - the length of the run.

public UpdateCRC ( byte b, int n ) : void
b byte the byte to include into the CRC.
n int the number of times that byte should be repeated.
return void