Class StreamDecoratorExtensions
Extension methods for the Stream class hidden behind the IDecorator<T> interface. This API supports the product infrastructure and is not intended to be used directly from your code.
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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.
CopyStream(IDecorator<Stream>, Stream, int, bool)
Reads the bytes from the enclosed Stream of the specified decorator and writes them to the destination.
public static void CopyStream(this IDecorator<Stream> decorator, Stream destination, int bufferSize = 81920, bool changePosition = true)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
destinationStreamThe Stream to which the contents of the current stream will be copied.
bufferSizeintThe size of the buffer. This value must be greater than zero. The default size is 81920.
changePositionboolif
true, the enclosed Stream of the specifieddecoratorwill temporarily have its position changed to 0; otherwise the position is left untouched.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CopyStreamAsync(IDecorator<Stream>, Stream, int, bool, CancellationToken)
Asynchronously reads the bytes from the enclosed Stream of the specified decorator and writes them to the destination.
public static Task CopyStreamAsync(this IDecorator<Stream> decorator, Stream destination, int bufferSize = 81920, bool changePosition = true, CancellationToken ct = default)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
destinationStreamThe Stream to which the contents of the current stream will be copied.
bufferSizeintThe size of the buffer. This value must be greater than zero. The default size is 81920.
changePositionboolif
true, the enclosed Stream of the specifieddecoratorwill temporarily have its position changed to 0; otherwise the position is left untouched.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
Exceptions
- ArgumentNullException
decoratorcannot 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratordoes not support write operations such as compression.- InvalidDataException
The enclosed Stream of
decoratorwas compressed using an unsupported compression method.
InvokeToByteArray(IDecorator<Stream>, int, bool)
Converts the enclosed Stream of the specified decorator to its equivalent byte[] representation. Not intended to be used directly from your code.
public static byte[] InvokeToByteArray(this IDecorator<Stream> decorator, int bufferSize = 81920, bool leaveOpen = false)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
bufferSizeintThe size of the buffer. This value must be greater than zero. The default size is 81920.
leaveOpenboolif
true, the Stream object is being left open; otherwise it is being closed and disposed.
Returns
- byte[]
Exceptions
- ArgumentNullException
decoratorcannot be null.
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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratorcannot 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
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- ArgumentException
The enclosed Stream of
decoratorcannot be read from.
ToEncodedString(IDecorator<Stream>, Action<StreamReaderOptions>)
public static string ToEncodedString(this IDecorator<Stream> decorator, Action<StreamReaderOptions> setup = null)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<StreamReaderOptions>The StreamReaderOptions which may be configured.
Returns
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
decoratorcannot be null.- InvalidEnumArgumentException
setupwas initialized with an invalid Preamble.
ToEncodedStringAsync(IDecorator<Stream>, Action<AsyncStreamReaderOptions>)
public static Task<string> ToEncodedStringAsync(this IDecorator<Stream> decorator, Action<AsyncStreamReaderOptions> setup = null)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
setupAction<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
decoratorcannot be null.- InvalidEnumArgumentException
setupwas 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)
Parameters
decoratorIDecorator<Stream>The IDecorator<T> to extend.
bufferbyte[]The buffer to write data from.
ctCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous write operation.
Exceptions
- ArgumentNullException
decoratoris null -or-bufferis null.- NotSupportedException
The enclosed Stream of
decoratordoes not support writing.- ObjectDisposedException
The enclosed Stream of
decoratorhas been disposed.- InvalidOperationException
The enclosed Stream of
decoratoris currently in use by a previous write operation.