Class StreamExtensions
- Namespace
- Cuemon.Extensions.IO
- Assembly
- Cuemon.Extensions.IO.dll
Extension methods for the Stream class.
public static class StreamExtensions
- Inheritance
-
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
StreamThe Stream to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
setup
Action<StreamCompressionOptions>The StreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCompressionOptions>The AsyncStreamCompressionOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- 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
StreamThe Stream to extend.
second
StreamThe Stream to concat with
first
.setup
Action<DisposableOptions>The DisposableOptions which may be configured.
Returns
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
StreamThe Stream to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<AsyncStreamCopyOptions>The AsyncStreamCopyOptions which may be configured.
Returns
Exceptions
- ArgumentNullException
value
cannot be null.- ArgumentException
value
does not support write operations such as compression.- 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
StreamThe Stream to extend.
setup
Action<StreamCopyOptions>The StreamCopyOptions which may be configured.
Returns
- Byte[]
A byte[] that is equivalent to
input
.
Exceptions
- ArgumentNullException
input
cannot be null.- 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
StreamThe 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
- ArgumentNullException
input
cannot be null.- 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
StreamThe Stream to be extended.
setup
Action<EncodingOptions>The EncodingOptions which may be configured.
Returns
- Char[]
A char[] that is equivalent to
input
.
Remarks
EncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
input
cannot be null.- ArgumentException
input
cannot be read from.- ArgumentOutOfRangeException
input
length is greater than MaxValue.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.
ToEncodedString(Stream, Action<StreamEncodingOptions>)
Converts the specified value
to a String.
public static string ToEncodedString(this Stream value, Action<StreamEncodingOptions> setup = null)
Parameters
value
StreamThe Stream to extend.
setup
Action<StreamEncodingOptions>The StreamReaderOptions which may be configured.
Returns
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
value
cannot be null.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.
ToEncodedStringAsync(Stream, Action<AsyncStreamEncodingOptions>)
Converts the specified value
to a String.
public static Task<string> ToEncodedStringAsync(this Stream value, Action<AsyncStreamEncodingOptions> setup = null)
Parameters
value
StreamThe 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 String containing the result of the specified
value
.
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
value
cannot be null.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.
TryDetectUnicodeEncoding(Stream, out Encoding)
public static bool TryDetectUnicodeEncoding(this Stream value, out Encoding result)
Parameters
value
StreamThe Stream to extend.
result
EncodingWhen this method returns, it contains the Unicode 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 thevalue
parameter is null, or does not contain a Unicode representation of an Encoding.
Returns
- Boolean
true
if thevalue
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
StreamThe Stream 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
stream
is null -or-buffer
is null.- NotSupportedException
The stream does not support writing.
- ObjectDisposedException
The stream has been disposed.
- InvalidOperationException
The stream is currently in use by a previous write operation.