Table of Contents

Class CRC32

Namespace
Ionic.Zlib
Assembly
SunamoDotNetZip.dll

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.

[Guid("ebc25cf6-9120-4283-b972-0e5520d0000C")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class CRC32
Inheritance
CRC32
Inherited Members
Extension Methods

Remarks

This type is used internally by DotNetZip; it is generally not used directly by applications wishing to create, read, or manipulate zip archive files.

Constructors

CRC32()

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

public CRC32()

CRC32(bool)

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

public CRC32(bool reverseBits)

Parameters

reverseBits bool

specify true if the instance should reverse data bits.

Remarks

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, bool)

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

public CRC32(int polynomial, bool reverseBits)

Parameters

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.

Remarks

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.

Properties

Crc32Result

Indicates the current CRC for all blocks slurped in.

public int Crc32Result { get; }

Property Value

int

TotalBytesRead

Indicates the total number of bytes applied to the CRC.

public long TotalBytesRead { get; }

Property Value

long

Methods

Combine(int, int)

Combines the given CRC32 value with the current running total.

public void Combine(int crc, int length)

Parameters

crc int

the crc value to be combined with this one

length int

the length of data the CRC value was calculated on

Remarks

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(int, byte)

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

public int ComputeCrc32(int word, byte byteValue)

Parameters

word int

The word to start with.

byteValue byte

The byte to combine it with.

Returns

int

The CRC-ized result.

GetCrc32(Stream)

Returns the CRC32 for the specified stream.

public int GetCrc32(Stream input)

Parameters

input Stream

The stream over which to calculate the CRC32

Returns

int

the CRC32 calculation

GetCrc32AndCopy(Stream, Stream)

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

public int GetCrc32AndCopy(Stream input, Stream output)

Parameters

input Stream

The stream over which to calculate the CRC32

output Stream

The stream into which to deflate the input

Returns

int

the CRC32 calculation

Reset()

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

public void Reset()

Remarks

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

SlurpBlock(byte[], int, int)

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 void SlurpBlock(byte[] block, int offset, int count)

Parameters

block byte[]

block of bytes to slurp

offset int

starting point in the block

count int

how many bytes within the block to slurp

UpdateCRC(byte)

Process one byte in the CRC.

public void UpdateCRC(byte byteValue)

Parameters

byteValue byte

the byte to include into the CRC .

UpdateCRC(byte, int)

Process a run of N identical bytes into the CRC.

public void UpdateCRC(byte byteValue, int repeatCount)

Parameters

byteValue byte

the byte to include into the CRC.

repeatCount int

the number of times that byte should be repeated.

Remarks

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.