Table of Contents

Class CrcCalculatorStream

Namespace
Ionic.Zlib
Assembly
SunamoDotNetZip.dll

A Stream that calculates a CRC32 (a checksum) on all bytes read, or on all bytes written.

public class CrcCalculatorStream : Stream, IAsyncDisposable, IDisposable
Inheritance
CrcCalculatorStream
Implements
Inherited Members
Extension Methods

Remarks

This class can be used to verify the CRC of a ZipEntry when reading from a stream, or to calculate a CRC when writing to a stream. The stream should be used to either read, or write, but not both. If you intermix reads and writes, the results are not defined.

This class is intended primarily for use internally by the DotNetZip library.

Constructors

CrcCalculatorStream(Stream)

The default constructor.

public CrcCalculatorStream(Stream stream)

Parameters

stream Stream

The underlying stream

Remarks

Instances returned from this constructor will leave the underlying stream open upon Close(). The stream uses the default CRC32 algorithm, which implies a polynomial of 0xEDB88320.

CrcCalculatorStream(Stream, bool)

The constructor allows the caller to specify how to handle the underlying stream at close.

public CrcCalculatorStream(Stream stream, bool leaveOpen)

Parameters

stream Stream

The underlying stream

leaveOpen bool

true to leave the underlying stream open upon close of the CrcCalculatorStream; false otherwise.

Remarks

The stream uses the default CRC32 algorithm, which implies a polynomial of 0xEDB88320.

CrcCalculatorStream(Stream, long)

A constructor allowing the specification of the length of the stream to read.

public CrcCalculatorStream(Stream stream, long length)

Parameters

stream Stream

The underlying stream

length long

The length of the stream to slurp

Remarks

The stream uses the default CRC32 algorithm, which implies a polynomial of 0xEDB88320.

Instances returned from this constructor will leave the underlying stream open upon Close().

CrcCalculatorStream(Stream, long, bool)

A constructor allowing the specification of the length of the stream to read, as well as whether to keep the underlying stream open upon Close().

public CrcCalculatorStream(Stream stream, long length, bool leaveOpen)

Parameters

stream Stream

The underlying stream

length long

The length of the stream to slurp

leaveOpen bool

true to leave the underlying stream open upon close of the CrcCalculatorStream; false otherwise.

Remarks

The stream uses the default CRC32 algorithm, which implies a polynomial of 0xEDB88320.

CrcCalculatorStream(Stream, long, bool, CRC32)

A constructor allowing the specification of the length of the stream to read, as well as whether to keep the underlying stream open upon Close(), and the CRC32 instance to use.

public CrcCalculatorStream(Stream stream, long length, bool leaveOpen, CRC32 crc32)

Parameters

stream Stream

The underlying stream

length long

The length of the stream to slurp

leaveOpen bool

true to leave the underlying stream open upon close of the CrcCalculatorStream; false otherwise.

crc32 CRC32

the CRC32 instance to use to calculate the CRC32

Remarks

The stream uses the specified CRC32 instance, which allows the application to specify how the CRC gets calculated.

Properties

CanRead

Indicates whether the stream supports reading.

public override bool CanRead { get; }

Property Value

bool

CanSeek

Indicates whether the stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

Remarks

Always returns false.

CanWrite

Indicates whether the stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

Crc

Provides the current CRC for all blocks slurped in.

public int Crc { get; }

Property Value

int

Remarks

The running total of the CRC is kept as data is written or read through the stream. read this property after all reads or writes to get an accurate CRC for the entire stream.

LeaveOpen

Indicates whether the underlying stream will be left open when the CrcCalculatorStream is Closed.

public bool LeaveOpen { get; set; }

Property Value

bool

Remarks

Set this at any point before calling Close().

Length

Returns the length of the underlying stream.

public override long Length { get; }

Property Value

long

Position

The getter for this property returns the total bytes read. If you use the setter, it will throw NotSupportedException.

public override long Position { get; set; }

Property Value

long

TotalBytesSlurped

Gets the total number of bytes run through the CRC32 calculator.

public long TotalBytesSlurped { get; }

Property Value

long

Remarks

This is either the total number of bytes read, or the total number of bytes written, depending on the direction of this stream.

Methods

Close()

Closes the stream.

public override void Close()

Flush()

Flush the stream.

public override void Flush()

Read(byte[], int, int)

Read from the stream

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

the buffer to read

offset int

the offset at which to start

count int

the number of bytes to read

Returns

int

the number of bytes actually read

Seek(long, SeekOrigin)

Seeking is not supported on this stream. This method always throws NotSupportedException

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

N/A

origin SeekOrigin

N/A

Returns

long

N/A

SetLength(long)

This method always throws NotSupportedException

public override void SetLength(long value)

Parameters

value long

N/A

Write(byte[], int, int)

Write to the stream.

public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

the buffer from which to write

offset int

the offset at which to start writing

count int

the number of bytes to write