New to Telerik Document ProcessingStart a free 30-day trial

Stream wrapper that compresses or decompresses data on the fly over a base stream, optionally applying checksum and encryption.

Definition

Namespace:Telerik.Windows.Zip

Assembly:Telerik.Windows.Zip.dll

Syntax:

C#
public class CompressedStream : OperationStream, IDisposable, IAsyncDisposable

Inheritance: objectMarshalByRefObjectStreamOperationStreamCompressedStream

Implements: IAsyncDisposableIDisposable

Inherited Members OperationStream.Flush()OperationStream.Read(byte[], int, int, CancellationToken)OperationStream.Seek(long, SeekOrigin)OperationStream.EnsureNotDisposed()OperationStream.CanReadOperationStream.CanSeekOperationStream.CanWriteOperationStream.HasFlushedFinalBlockOperationStream.LengthOperationStream.PositionOperationStream.TotalPlainCountOperationStream.TotalTransformedCountStream.NullStream.CopyTo(Stream)Stream.CopyTo(Stream, int)Stream.CopyToAsync(Stream)Stream.CopyToAsync(Stream, int)Stream.CopyToAsync(Stream, CancellationToken)Stream.CopyToAsync(Stream, int, CancellationToken)Stream.Dispose()Stream.Close()Stream.DisposeAsync()Stream.FlushAsync()Stream.FlushAsync(CancellationToken)Stream.CreateWaitHandle()Stream.BeginRead(byte[], int, int, AsyncCallback, object)Stream.EndRead(IAsyncResult)Stream.ReadAsync(byte[], int, int)Stream.ReadAsync(Memory<byte>, CancellationToken)Stream.ReadExactlyAsync(Memory<byte>, CancellationToken)Stream.ReadExactlyAsync(byte[], int, int, CancellationToken)Stream.ReadAtLeastAsync(Memory<byte>, int, bool, CancellationToken)Stream.BeginWrite(byte[], int, int, AsyncCallback, object)Stream.EndWrite(IAsyncResult)Stream.WriteAsync(byte[], int, int)Stream.WriteAsync(byte[], int, int, CancellationToken)Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)Stream.Read(Span<byte>)Stream.ReadByte()Stream.ReadExactly(Span<byte>)Stream.ReadExactly(byte[], int, int)Stream.ReadAtLeast(Span<byte>, int, bool)Stream.Write(ReadOnlySpan<byte>)Stream.WriteByte(byte)Stream.Synchronized(Stream)Stream.ObjectInvariant()Stream.ValidateBufferArguments(byte[], int, int)Stream.ValidateCopyToArguments(Stream, int)Stream.CanTimeoutStream.ReadTimeoutStream.WriteTimeoutMarshalByRefObject.GetLifetimeService()MarshalByRefObject.InitializeLifetimeService()MarshalByRefObject.MemberwiseClone(bool)...

Constructors

Creates a compression or decompression stream with explicit checksum and encryption options.

C#
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Crc")]
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings, bool useCrc32, EncryptionSettingsBase encryptionSettings)
Parameters:baseStreamStream

The base input/output stream.

modeStreamOperationMode

Stream operational mode.

settingsCompressionSettings

Compression settings.

useCrc32bool

Indicates whether the CRC32 (true) or Adler32 (false) checksum algorithm will be used.

encryptionSettingsEncryptionSettingsBase

Encryption settings.

Exceptions:

ArgumentOutOfRangeException

Specified mode is not allowed for the given stream.

Creates a compression or decompression stream using the specified settings.

C#
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings)
Parameters:baseStreamStream

The base input/output stream.

modeStreamOperationMode

Stream operational mode.

settingsCompressionSettings

Compression settings.

Exceptions:

ArgumentOutOfRangeException

Specified mode is not allowed for the given stream.

Events

Raised when checksum calculation completes for the processed data segment.

C#
public event EventHandler ChecksumReady

Methods

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

C#
[SuppressMessage("Microsoft.Usage", "CA2215:Dispose methods should call base class dispose")]
protected override void Dispose(bool disposing)
Parameters:disposingbool

Value which indicates whether both managed and unmanaged resources (true) on only unmanaged resources (false) should be released.

Overrides: OperationStream.Dispose(bool)

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

C#
public override int Read(byte[] buffer, int offset, int count)
Parameters:bufferbyte[]

An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

offsetint

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

countint

The maximum number of bytes to be read from the current stream.

Returns:

int

The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

Exceptions:

NotSupportedException

The StreamOperationMode associated with current OperationStream object does not match the underlying stream.
For example, this exception is thrown when using Read with an underlying stream that is write only.

ArgumentOutOfRangeException

The offset parameter is less than zero.-or- The count parameter is less than zero.

ArgumentException

The sum of the count and offset parameters is larger than the length of the buffer.

Overrides: OperationStream.Read(byte[], int, int)

Reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

C#
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters:bufferbyte[]

An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

offsetint

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

countint

The maximum number of bytes to be read from the current stream.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns:

Task<int>

A task returning the total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

Overrides: Stream.ReadAsync(byte[], int, int, CancellationToken)

Sets the length of the current stream.

C#
public override void SetLength(long value)
Parameters:valuelong

The desired length of the current stream in bytes.

Overrides: OperationStream.SetLength(long)

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

C#
public override void Write(byte[] buffer, int offset, int count)
Parameters:bufferbyte[]

An array of bytes. This method copies count bytes from buffer to the current stream.

offsetint

The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

countint

The number of bytes to be written to the current stream.

Overrides: OperationStream.Write(byte[], int, int)

Properties

Gets the running checksum (CRC32 or Adler32) accumulated from the first read/write until Flush.

C#
public long Checksum { get; }

Gets the total compressed byte count including any encryption header bytes.

C#
public long CompressedSize { get; }