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:
public class CompressedStream : OperationStream, IDisposable, IAsyncDisposable
Inheritance: objectMarshalByRefObjectStreamOperationStreamCompressedStream
Implements:
Inherited Members
Constructors
Creates a compression or decompression stream with explicit checksum and encryption options.
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Crc")]
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings, bool useCrc32, EncryptionSettingsBase encryptionSettings)
The base input/output stream.
modeStreamOperationModeStream operational mode.
settingsCompressionSettingsCompression settings.
useCrc32boolIndicates whether the CRC32 (true) or Adler32 (false) checksum algorithm will be used.
encryptionSettingsEncryptionSettingsBaseEncryption settings.
Exceptions:Specified mode is not allowed for the given stream.
Creates a compression or decompression stream using the specified settings.
public CompressedStream(Stream baseStream, StreamOperationMode mode, CompressionSettings settings)
The base input/output stream.
modeStreamOperationModeStream operational mode.
settingsCompressionSettingsCompression settings.
Exceptions:Specified mode is not allowed for the given stream.
Events
Raised when checksum calculation completes for the processed data segment.
public event EventHandler ChecksumReady
Methods
Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
[SuppressMessage("Microsoft.Usage", "CA2215:Dispose methods should call base class dispose")]
protected override void Dispose(bool disposing)
Value which indicates whether both managed and unmanaged resources (true) on only unmanaged resources (false) should be released.
Overrides:
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
public override int Read(byte[] buffer, int offset, int count)
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.
offsetintThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countintThe maximum number of bytes to be read from the current stream.
Returns: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: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.
The offset parameter is less than zero.-or- The count parameter is less than zero.
The sum of the count and offset parameters is larger than the length of the buffer.
Overrides:
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.
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
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.
offsetintThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countintThe maximum number of bytes to be read from the current stream.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns: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:
Sets the length of the current stream.
public override void SetLength(long value)
The desired length of the current stream in bytes.
Overrides:
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public override void Write(byte[] buffer, int offset, int count)
An array of bytes. This method copies count bytes from buffer to the current stream.
offsetintThe zero-based byte offset in buffer at which to begin copying bytes to the current stream.
countintThe number of bytes to be written to the current stream.
Overrides:
Properties
Gets the running checksum (CRC32 or Adler32) accumulated from the first read/write until Flush.
public long Checksum { get; }
Gets the total compressed byte count including any encryption header bytes.
public long CompressedSize { get; }