New to Telerik Document ProcessingStart a free 30-day trial

Extensions for the Stream class.

Definition

Namespace:Telerik.Windows.Zip.Utilities

Assembly:Telerik.Windows.Zip.dll

Syntax:

C#
public static class StreamExtensions

Inheritance: objectStreamExtensions

Methods

Reads the bytes from the current stream and writes them to another stream.

C#
public static void CopyTo(this Stream source, Stream destination, TimeSpan? timeout)
Parameters:sourceStream

The stream from which the contents will be copied to another stream.

destinationStream

The stream to which the contents of the current stream will be copied.

timeoutTimeSpan?

The time period after which the operation will be cancelled.

Asynchronously reads the bytes from the current stream and writes them to another stream. Both streams positions are advanced by the number of bytes copied.

C#
public static Task CopyToAsync(this Stream source, Stream destination, CancellationToken cancellationToken)
Parameters:sourceStreamdestinationStream

The stream to which the contents of the current stream will be copied.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns:

Task

A task that represents the asynchronous copy operation.

Reads count number of bytes from the current stream and advances the position within the stream.

C#
public static byte[] ReadExactly(this Stream stream, byte[] buffer, int offset, int count)
Parameters:streamStream

The stream to read from.

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 stream.

offsetint

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

countint

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

Returns:

byte[]

Exceptions:

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset is outside the bounds of buffer. -or- count is negative. -or- The range specified by the combination of offset and count exceeds the length of buffer.

EndOfStreamException

The end of the stream is reached before reading count number of bytes.

Remarks:

When count is 0 (zero), this read operation will be completed without waiting for available data in the stream.