Class StreamDecoratorExtensions
- Namespace
- Cuemon.IO
- Assembly
- Cuemon.IO.dll
Extension methods for the Stream class hidden behind the IDecorator<T> interface.
public static class StreamDecoratorExtensions
- Inheritance
-
StreamDecoratorExtensions
Methods
CompressBrotli(IDecorator<Stream>, Action<StreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the Brotli
algorithm.
public static Stream CompressBrotli(this IDecorator<Stream> decorator, Action<StreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CompressBrotliAsync(IDecorator<Stream>, Action<AsyncStreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the Brotli
algorithm.
public static Task<Stream> CompressBrotliAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a compressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CompressDeflate(IDecorator<Stream>, Action<StreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the Deflate
algorithm.
public static Stream CompressDeflate(this IDecorator<Stream> decorator, Action<StreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CompressDeflateAsync(IDecorator<Stream>, Action<AsyncStreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the Deflate
algorithm.
public static Task<Stream> CompressDeflateAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a compressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CompressGZip(IDecorator<Stream>, Action<StreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the GZip
algorithm.
public static Stream CompressGZip(this IDecorator<Stream> decorator, Action<StreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CompressGZipAsync(IDecorator<Stream>, Action<AsyncStreamCompressionOptions>)
Compress the enclosed Stream of the specified decorator
using the GZip
algorithm.
public static Task<Stream> CompressGZipAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCompressionOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a compressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.
CopyStreamAsync(IDecorator<Stream>, Stream, Int32, Boolean, CancellationToken)
Asynchronously reads the bytes from the enclosed Stream of the specified decorator
and writes them to the destination
.
public static async Task CopyStreamAsync(this IDecorator<Stream> decorator, Stream destination, int bufferSize = 81920, bool changePosition = true, CancellationToken ct = default(CancellationToken))
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
destination
StreamThe Stream to which the contents of the current stream will be copied.
bufferSize
Int32The size of the buffer. This value must be greater than zero. The default size is 81920.
changePosition
Booleanif
true
, the enclosed Stream of the specifieddecorator
will temporarily have its position changed to 0; otherwise the position is left untouched.ct
CancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.
DecompressBrotli(IDecorator<Stream>, Action<StreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using Brotli
data format specification.
public static Stream DecompressBrotli(this IDecorator<Stream> decorator, Action<StreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
DecompressBrotliAsync(IDecorator<Stream>, Action<AsyncStreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using Brotli
data format specification.
public static Task<Stream> DecompressBrotliAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a decompressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
DecompressDeflate(IDecorator<Stream>, Action<StreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using Deflate
data format specification.
public static Stream DecompressDeflate(this IDecorator<Stream> decorator, Action<StreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
DecompressDeflateAsync(IDecorator<Stream>, Action<AsyncStreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using Deflate
data format specification.
public static Task<Stream> DecompressDeflateAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a decompressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
DecompressGZip(IDecorator<Stream>, Action<StreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using GZip
data format specification.
public static Stream DecompressGZip(this IDecorator<Stream> decorator, Action<StreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
DecompressGZipAsync(IDecorator<Stream>, Action<AsyncStreamCopyOptions>)
Decompress the enclosed Stream of the specified decorator
using GZip
data format specification.
public static Task<Stream> DecompressGZipAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
- Task<Stream>
A task that represents the asynchronous operation. The task result contains a decompressed version of the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
does not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decorator
was compressed using an unsupported compression method.
ToByteArray(IDecorator<Stream>, Action<StreamCopyOptions>)
Converts the enclosed Stream of the specified decorator
to its equivalent byte[] representation.
public static byte[] ToByteArray(this IDecorator<Stream> decorator, Action<StreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
cannot be read from.
ToByteArrayAsync(IDecorator<Stream>, Action<AsyncStreamCopyOptions>)
Converts the enclosed Stream of the specified decorator
to its equivalent byte[] representation.
public static Task<byte[]> ToByteArrayAsync(this IDecorator<Stream> decorator, Action<AsyncStreamCopyOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> 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 the enclosed Stream of the specified
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.- ArgumentException
The enclosed Stream of
decorator
cannot be read from.
ToEncodedString(IDecorator<Stream>, Action<StreamReaderOptions>)
public static string ToEncodedString(this IDecorator<Stream> decorator, Action<StreamReaderOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<StreamReaderOptions>The StreamReaderOptions which may be configured.
Returns
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
decorator
cannot be null.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.
ToEncodedStringAsync(IDecorator<Stream>, Action<AsyncStreamReaderOptions>)
public static Task<string> ToEncodedStringAsync(this IDecorator<Stream> decorator, Action<AsyncStreamReaderOptions> setup = null)
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
setup
Action<AsyncStreamReaderOptions>The AsyncStreamReaderOptions which may be configured.
Returns
- Task<String>
A task that represents the asynchronous operation. The task result contains a String containing the result of the enclosed Stream of the specified
decorator
.
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
decorator
cannot be null.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.
WriteAllAsync(IDecorator<Stream>, Byte[], CancellationToken)
Asynchronously writes a sequence of bytes to the enclosed Stream of the decorator
with the entire size of the buffer
starting from position 0.
public static Task WriteAllAsync(this IDecorator<Stream> decorator, byte[] buffer, CancellationToken ct = default(CancellationToken))
Parameters
decorator
IDecorator<Stream>The IDecorator<T> to extend.
buffer
Byte[]The buffer to write data from.
ct
CancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ArgumentNullException
decorator
is null -or-buffer
is null.- NotSupportedException
The enclosed Stream of
decorator
does not support writing.- ObjectDisposedException
The enclosed Stream of
decorator
has been disposed.- InvalidOperationException
The enclosed Stream of
decorator
is currently in use by a previous write operation.