Class
CompressedStream

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:

cs-api-definition
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

CompressedStream(Stream, StreamOperationMode, CompressionSettings)

Creates a compression or decompression stream using the specified settings.

Declaration

cs-api-definition
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings)

Parameters

baseStream

Stream

The base input/output stream.

mode

StreamOperationMode

Stream operational mode.

settings

CompressionSettings

Compression settings.

Exceptions

ArgumentOutOfRangeException

Specified mode is not allowed for the given stream.

CompressedStream(Stream, StreamOperationMode, CompressionSettings, bool, EncryptionSettingsBase)

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

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Crc")]
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings, bool useCrc32, EncryptionSettingsBase encryptionSettings)

Parameters

baseStream

Stream

The base input/output stream.

mode

StreamOperationMode

Stream operational mode.

settings

CompressionSettings

Compression settings.

useCrc32

bool

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

encryptionSettings

EncryptionSettingsBase

Encryption settings.

Exceptions

ArgumentOutOfRangeException

Specified mode is not allowed for the given stream.

Properties

Checksum

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

Declaration

cs-api-definition
public long Checksum { get; }

Property Value

long

CompressedSize

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

Declaration

cs-api-definition
public long CompressedSize { get; }

Property Value

long

Methods

Dispose(bool)

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

Declaration

cs-api-definition
[SuppressMessage("Microsoft.Usage", "CA2215:Dispose methods should call base class dispose")]
protected override void Dispose(bool disposing)

Parameters

disposing

bool

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

Overrides OperationStream.Dispose(bool)

Read(byte[], int, int)

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

Declaration

cs-api-definition
public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer

byte[]

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.

offset

int

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

count

int

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)

ReadAsync(byte[], int, int, CancellationToken)

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.

Declaration

cs-api-definition
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

Parameters

buffer

byte[]

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.

offset

int

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

count

int

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

cancellationToken

CancellationToken

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)

SetLength(long)

Sets the length of the current stream.

Declaration

cs-api-definition
public override void SetLength(long value)

Parameters

value

long

The desired length of the current stream in bytes.

Overrides OperationStream.SetLength(long)

Write(byte[], int, int)

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

Declaration

cs-api-definition
public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer

byte[]

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

offset

int

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

count

int

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

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

Events

ChecksumReady

Raised when checksum calculation completes for the processed data segment.

Declaration

cs-api-definition
public event EventHandler ChecksumReady

Event Value

EventHandler