Table of Contents

Class StreamExtensions

Namespace
Cuemon.Extensions.IO
Assembly
Cuemon.Extensions.IO.dll

Extension methods for the System.IO.Stream class.

public static class StreamExtensions
Inheritance
Object
StreamExtensions

Methods

CompressBrotli(Stream, Action<StreamCompressionOptions>)

Compresses the value using the BROTLI algorithm.

public static Stream CompressBrotli(this Stream value, Action<StreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCompressionOptions>

The StreamCompressionOptions which may be configured.

Returns

Stream

A BROTLI compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

CompressBrotliAsync(Stream, Action<AsyncStreamCompressionOptions>)

Compresses the value using the BROTLI algorithm.

public static Task<Stream> CompressBrotliAsync(this Stream value, Action<AsyncStreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCompressionOptions>

The AsyncStreamCompressionOptions which may be configured.

Returns

Task<Stream>

A DEFLATE compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

CompressDeflate(Stream, Action<StreamCompressionOptions>)

Compresses the value using the DEFLATE algorithm.

public static Stream CompressDeflate(this Stream value, Action<StreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCompressionOptions>

The StreamCompressionOptions which may be configured.

Returns

Stream

A DEFLATE compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

CompressDeflateAsync(Stream, Action<AsyncStreamCompressionOptions>)

Compresses the value using the DEFLATE algorithm.

public static Task<Stream> CompressDeflateAsync(this Stream value, Action<AsyncStreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCompressionOptions>

The AsyncStreamCompressionOptions which may be configured.

Returns

Task<Stream>

A DEFLATE compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

CompressGZip(Stream, Action<StreamCompressionOptions>)

Compresses the value using the GZIP algorithm.

public static Stream CompressGZip(this Stream value, Action<StreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCompressionOptions>

The StreamCompressionOptions which may be configured.

Returns

Stream

A GZIP compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

CompressGZipAsync(Stream, Action<AsyncStreamCompressionOptions>)

Compresses the value using the GZIP algorithm.

public static Task<Stream> CompressGZipAsync(this Stream value, Action<AsyncStreamCompressionOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCompressionOptions>

The AsyncStreamCompressionOptions which may be configured.

Returns

Task<Stream>

A DEFLATE compressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

Concat(Stream, Stream, Action<DisposableOptions>)

Combines two streams, first and second, into one stream.

public static Stream Concat(this Stream first, Stream second, Action<DisposableOptions> setup = null)

Parameters

first Stream

The System.IO.Stream to extend.

second Stream

The System.IO.Stream to concat with first.

setup Action<DisposableOptions>

The DisposableOptions which may be configured.

Returns

Stream

The concatenated System.IO.Stream representations of values first and second.

DecompressBrotli(Stream, Action<StreamCopyOptions>)

Decompresses the value using the BROTLI data format specification.

public static Stream DecompressBrotli(this Stream value, Action<StreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCopyOptions>

The StreamCopyOptions which may be configured.

Returns

Stream

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

DecompressBrotliAsync(Stream, Action<AsyncStreamCopyOptions>)

Decompresses the value using the BROTLI data format specification.

public static Task<Stream> DecompressBrotliAsync(this Stream value, Action<AsyncStreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCopyOptions>

The AsyncStreamCopyOptions which may be configured.

Returns

Task<Stream>

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

DecompressDeflate(Stream, Action<StreamCopyOptions>)

Decompresses the value using the DEFLATE data format specification.

public static Stream DecompressDeflate(this Stream value, Action<StreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCopyOptions>

The StreamCopyOptions which may be configured.

Returns

Stream

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

DecompressDeflateAsync(Stream, Action<AsyncStreamCopyOptions>)

Decompresses the value using the DEFLATE data format specification.

public static Task<Stream> DecompressDeflateAsync(this Stream value, Action<AsyncStreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCopyOptions>

The AsyncStreamCopyOptions which may be configured.

Returns

Task<Stream>

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

DecompressGZip(Stream, Action<StreamCopyOptions>)

Decompresses the value using the GZIP data format specification.

public static Stream DecompressGZip(this Stream value, Action<StreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamCopyOptions>

The StreamCopyOptions which may be configured.

Returns

Stream

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

DecompressGZipAsync(Stream, Action<AsyncStreamCopyOptions>)

Decompresses the value using the GZIP data format specification.

public static Task<Stream> DecompressGZipAsync(this Stream value, Action<AsyncStreamCopyOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCopyOptions>

The AsyncStreamCopyOptions which may be configured.

Returns

Task<Stream>

A decompressed System.IO.Stream of the value.

Exceptions

System.ArgumentNullException

value cannot be null.

System.ArgumentException

value does not support write operations such as compression.

System.IO.InvalidDataException

value was compressed using an unsupported compression method.

ToByteArray(Stream, Action<StreamCopyOptions>)

Converts the specified input to its equivalent byte[] representation.

public static byte[] ToByteArray(this Stream input, Action<StreamCopyOptions> setup = null)

Parameters

input Stream

The System.IO.Stream to extend.

setup Action<StreamCopyOptions>

The StreamCopyOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

Exceptions

System.ArgumentNullException

input cannot be null.

System.ArgumentException

input cannot be read from.

ToByteArrayAsync(Stream, Action<AsyncStreamCopyOptions>)

Converts the specified input to its equivalent byte[] representation.

public static Task<byte[]> ToByteArrayAsync(this Stream input, Action<AsyncStreamCopyOptions> setup = null)

Parameters

input Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamCopyOptions>

The AsyncStreamCopyOptions which may be configured.

Returns

Task<Byte[]>

A task that represents the asynchronous operation. The task result contains a byte[] that is equivalent to input.

Exceptions

System.ArgumentNullException

input cannot be null.

System.ArgumentException

input cannot be read from.

ToCharArray(Stream, Action<EncodingOptions>)

Converts the specified input to its equivalent char[] representation.

public static char[] ToCharArray(this Stream input, Action<EncodingOptions> setup = null)

Parameters

input Stream

The System.IO.Stream to be extended.

setup Action<EncodingOptions>

The EncodingOptions which may be configured.

Returns

Char[]

A char[] that is equivalent to input.

Remarks

Exceptions

System.ArgumentNullException

input cannot be null.

System.ArgumentException

input cannot be read from.

System.ArgumentOutOfRangeException

input length is greater than System.Int32.MaxValue.

System.ComponentModel.InvalidEnumArgumentException

setup was initialized with an invalid Preamble.

ToEncodedString(Stream, Action<StreamEncodingOptions>)

Converts the specified value to a System.String.

public static string ToEncodedString(this Stream value, Action<StreamEncodingOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<StreamEncodingOptions>

The StreamReaderOptions which may be configured.

Returns

String

A System.String containing the result of the specified value.

Remarks

Exceptions

System.ArgumentNullException

value cannot be null.

System.ComponentModel.InvalidEnumArgumentException

setup was initialized with an invalid Preamble.

ToEncodedStringAsync(Stream, Action<AsyncStreamEncodingOptions>)

Converts the specified value to a System.String.

public static Task<string> ToEncodedStringAsync(this Stream value, Action<AsyncStreamEncodingOptions> setup = null)

Parameters

value Stream

The System.IO.Stream to extend.

setup Action<AsyncStreamEncodingOptions>

The AsyncStreamEncodingOptions which may be configured.

Returns

Task<String>

A task that represents the asynchronous operation. The task result contains a System.String containing the result of the specified value.

Remarks

Exceptions

System.ArgumentNullException

value cannot be null.

System.ComponentModel.InvalidEnumArgumentException

setup was initialized with an invalid Preamble.

TryDetectUnicodeEncoding(Stream, out Encoding)

Tries to resolve the Unicode System.Text.Encoding object from the specified System.IO.Stream object.

public static bool TryDetectUnicodeEncoding(this Stream value, out Encoding result)

Parameters

value Stream

The System.IO.Stream to extend.

result Encoding

When this method returns, it contains the Unicode System.Text.Encoding value equivalent to the encoding contained in value, if the conversion succeeded, or a null reference (Nothing in Visual Basic) if the conversion failed. The conversion fails if the value parameter is null, or does not contain a Unicode representation of an System.Text.Encoding.

Returns

Boolean

true if the value parameter was converted successfully; otherwise, false.

WriteAllAsync(Stream, Byte[], CancellationToken)

Asynchronously writes a sequence of bytes to the current stream with the entire size of the buffer starting from position 0.

public static Task WriteAllAsync(this Stream stream, byte[] buffer, CancellationToken ct = default(CancellationToken))

Parameters

stream Stream

The System.IO.Stream to extend.

buffer Byte[]

The buffer to write data from.

ct CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

System.ArgumentNullException

stream is null -or- buffer is null.

System.NotSupportedException

The stream does not support writing.

System.ObjectDisposedException

The stream has been disposed.

System.InvalidOperationException

The stream is currently in use by a previous write operation.