Represents high-level read/write methods for the stream.
InheritanceStreamExtensions
Namespace: DotNext.IO Assembly: DotNext.IO.dll Syntaxpublic static class StreamExtensions
Methods | Edit this page View Source AsUnbufferedStream(SafeFileHandle, FileAccess)
Creates a stream for the specified file handle.
Declarationpublic static Stream AsUnbufferedStream(this SafeFileHandle handle, FileAccess access)
Parameters Returns Type Description Stream
The unbuffered file stream.
Remarks Exceptions | Edit this page View Source Combine(IEnumerable<Stream>, bool)Combines multiple readable streams.
Declarationpublic static Stream Combine(this IEnumerable<Stream> streams, bool leaveOpen = true)
Parameters Type Name Description IEnumerable<Stream> streams
A collection of streams.
bool leaveOpentrue to keep the wrapped streams alive when combined stream disposed; otherwise, false.
Returns Type Description StreamAn object that represents multiple streams as one logical stream.
Exceptions | Edit this page View Source Combine(Stream, ReadOnlySpan<Stream>)Combines multiple readable streams.
Declarationpublic static Stream Combine(this Stream stream, ReadOnlySpan<Stream> others)
Parameters Returns Type Description Stream
An object that represents multiple streams as one logical stream.
| Edit this page View Source Combine(ReadOnlySpan<Stream>, bool)Combines multiple readable streams.
Declarationpublic static Stream Combine(this ReadOnlySpan<Stream> streams, bool leaveOpen = true)
Parameters Type Name Description ReadOnlySpan<Stream> streams
A collection of streams.
bool leaveOpentrue to keep the wrapped streams alive when combined stream disposed; otherwise, false.
Returns Type Description StreamAn object that represents multiple streams as one logical stream.
Exceptions | Edit this page View Source CopyToAsync(Stream, IBufferWriter<byte>, int, CancellationToken)Asynchronously reads the bytes from the current stream and writes them to buffer writer, using a specified cancellation token.
Declarationpublic static ValueTask CopyToAsync(this Stream source, IBufferWriter<byte> destination, int bufferSize = 0, CancellationToken token = default)
Parameters Type Name Description Stream source
The source stream.
IBufferWriter<byte> destinationThe writer to which the contents of the current stream will be copied.
int bufferSizeThe size, in bytes, of the buffer.
CancellationToken tokenThe token to monitor for cancellation requests.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Exceptions | Edit this page View Source CopyToAsync(Stream, IBufferWriter<byte>, long, int, CancellationToken)Asynchronously reads the bytes from the current stream and writes them to buffer writer, using a specified cancellation token.
Declarationpublic static ValueTask CopyToAsync(this Stream source, IBufferWriter<byte> destination, long count, int bufferSize = 0, CancellationToken token = default)
Parameters Type Name Description Stream source
The source stream.
IBufferWriter<byte> destinationThe writer to which the contents of the current stream will be copied.
long countThe number of bytes to copy.
int bufferSizeThe size, in bytes, of the buffer.
CancellationToken tokenThe token to monitor for cancellation requests.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Exceptions | Edit this page View Source CopyToAsync(Stream, Stream, long, Memory<byte>, CancellationToken)Asynchronously reads the bytes from the source stream and writes them to another stream, using a specified buffer.
Declarationpublic static ValueTask CopyToAsync(this Stream source, Stream destination, long count, Memory<byte> buffer, CancellationToken token = default)
Parameters Type Name Description Stream source
The source stream to read from.
Stream destinationThe destination stream to write into.
long countThe number of bytes to copy.
Memory<byte> bufferThe buffer used to hold copied content temporarily.
CancellationToken tokenThe token that can be used to cancel this operation.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Exceptions | Edit this page View Source CopyToAsync(Stream, Stream, Memory<byte>, CancellationToken)Asynchronously reads the bytes from the source stream and writes them to another stream, using a specified buffer.
Declarationpublic static ValueTask CopyToAsync(this Stream source, Stream destination, Memory<byte> buffer, CancellationToken token = default)
Parameters Type Name Description Stream source
The source stream to read from.
Stream destinationThe destination stream to write into.
Memory<byte> bufferThe buffer used to hold copied content temporarily.
CancellationToken tokenThe token that can be used to cancel this operation.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Exceptions | Edit this page View Source CopyToAsync<TConsumer>(Stream, TConsumer, long, Memory<byte>, CancellationToken)Asynchronously reads the bytes from the source stream and passes them to the consumer, using a specified buffer.
Declarationpublic static ValueTask CopyToAsync<TConsumer>(this Stream source, TConsumer consumer, long count, Memory<byte> buffer, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
Parameters Type Name Description Stream source
The source stream to read from.
TConsumer consumerThe destination stream to write into.
long countThe number of bytes to copy.
Memory<byte> bufferThe buffer used to hold copied content temporarily.
CancellationToken tokenThe token that can be used to cancel this operation.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source CopyToAsync<TConsumer>(Stream, TConsumer, Memory<byte>, CancellationToken)Asynchronously reads the bytes from the source stream and passes them to the consumer, using a specified buffer.
Declarationpublic static ValueTask CopyToAsync<TConsumer>(this Stream source, TConsumer consumer, Memory<byte> buffer, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
Parameters Type Name Description Stream source
The source stream to read from.
TConsumer consumerThe destination stream to write into.
Memory<byte> bufferThe buffer used to hold copied content temporarily.
CancellationToken tokenThe token that can be used to cancel this operation.
Returns Type Description ValueTaskThe task representing asynchronous execution of this method.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)Reads a length-prefixed string asynchronously using the specified encoding and supplied reusable buffer.
Declarationpublic static ValueTask<MemoryOwner<char>> DecodeAsync(this Stream stream, DecodingContext context, LengthFormat lengthFormat, Memory<byte> buffer, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to read from.
DecodingContext contextThe text decoding context.
LengthFormat lengthFormatThe format of the string length encoded in the stream.
Memory<byte> bufferThe buffer that is allocated by the caller.
MemoryAllocator<char> allocatorThe allocator of the buffer of characters.
CancellationToken tokenThe token that can be used to cancel asynchronous operation.
Returns Exceptions | Edit this page View Source DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<char>, Memory<byte>, CancellationToken)Decodes the sequence of characters.
Declarationpublic static IAsyncEnumerable<ReadOnlyMemory<char>> DecodeAsync(this Stream stream, DecodingContext context, LengthFormat lengthFormat, Memory<char> charBuffer, Memory<byte> byteBuffer, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to read from.
DecodingContext contextThe decoding context containing string characters encoding.
LengthFormat lengthFormatThe format of the string length encoded in the stream.
Memory<char> charBufferThe buffer of characters.
Memory<byte> byteBufferThe buffer of bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source EncodeAsync(Stream, ReadOnlyMemory<char>, EncodingContext, LengthFormat?, Memory<byte>, CancellationToken)Writes a length-prefixed or raw string to the stream asynchronously using supplied reusable buffer.
Declarationpublic static ValueTask<long> EncodeAsync(this Stream stream, ReadOnlyMemory<char> chars, EncodingContext context, LengthFormat? lengthFormat, Memory<byte> buffer, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to write into.
ReadOnlyMemory<char> charsThe string to be encoded.
EncodingContext contextThe encoding context.
LengthFormat? lengthFormatString length encoding format; or null to prevent encoding of string length.
Memory<byte> bufferThe buffer allocated by the caller needed for characters encoding.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<long>The task representing asynchronous state of the operation.
Exceptions | Edit this page View Source FormatAsync<T>(Stream, T, EncodingContext, LengthFormat?, Memory<byte>, string?, IFormatProvider?, MemoryAllocator<char>?, CancellationToken)Encodes formattable value as a set of characters using the specified encoding.
Declarationpublic static ValueTask<long> FormatAsync<T>(this Stream stream, T value, EncodingContext context, LengthFormat? lengthFormat, Memory<byte> buffer, string? format = null, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null, CancellationToken token = default) where T : ISpanFormattable
Parameters Type Name Description Stream stream
The stream to write into.
T valueThe type value to be written as string.
EncodingContext contextThe context describing encoding of characters.
LengthFormat? lengthFormatString length encoding format; or null to prevent encoding of string length.
Memory<byte> bufferThe buffer to be used for characters encoding.
string formatThe format of the value.
IFormatProvider providerThe format provider.
MemoryAllocator<char> allocatorA memory allocator for internal buffer of chars.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Parameters Name Description TThe type of formattable value.
Exceptions | Edit this page View Source FormatAsync<T>(Stream, T, LengthFormat?, Memory<byte>, string?, IFormatProvider?, CancellationToken)Encodes formattable value as a set of UTf-8 encoded characters.
Declarationpublic static ValueTask<int> FormatAsync<T>(this Stream stream, T value, LengthFormat? lengthFormat, Memory<byte> buffer, string? format = null, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanFormattable
Parameters Type Name Description Stream stream
The stream to write into.
T valueThe type value to be written as string.
LengthFormat? lengthFormatString length encoding format.
Memory<byte> bufferThe buffer to be used for characters encoding.
string formatThe format of the value.
IFormatProvider providerThe format provider.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The number of written bytes.
Type Parameters Name Description TThe type of formattable value.
Exceptions | Edit this page View Source ParseAsync<T>(Stream, LengthFormat, Memory<byte>, NumberStyles, IFormatProvider?, CancellationToken)Parses the numeric value from UTF-8 encoded characters.
Declarationpublic static ValueTask<T> ParseAsync<T>(this Stream stream, LengthFormat lengthFormat, Memory<byte> buffer, NumberStyles style, IFormatProvider? provider = null, CancellationToken token = default) where T : INumberBase<T>
Parameters Type Name Description Stream stream
The stream to read from.
LengthFormat lengthFormatThe format of the string length (in bytes) encoded in the stream.
Memory<byte> bufferThe buffer that is allocated by the caller.
NumberStyles styleA combination of number styles.
IFormatProvider providerCulture-specific formatting information.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The result of parsing.
Type Parameters Name Description TThe numeric type.
Exceptions | Edit this page View Source ParseAsync<T>(Stream, LengthFormat, Memory<byte>, IFormatProvider?, CancellationToken)Parses the sequence of characters encoded as UTF-8.
Declarationpublic static ValueTask<T> ParseAsync<T>(this Stream stream, LengthFormat lengthFormat, Memory<byte> buffer, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanParsable<T>
Parameters Type Name Description Stream stream
The stream to read from.
LengthFormat lengthFormatThe format of the string length (in bytes) encoded in the stream.
Memory<byte> bufferThe buffer that is allocated by the caller.
IFormatProvider providerCulture-specific formatting information.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The result of parsing.
Type Parameters Name Description TThe type that supports parsing from UTF-8.
Exceptions | Edit this page View Source ParseAsync<TArg, TResult>(Stream, TArg, ReadOnlySpanFunc<char, TArg, TResult>, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)Parses the sequence of characters.
Declarationpublic static ValueTask<TResult> ParseAsync<TArg, TResult>(this Stream stream, TArg arg, ReadOnlySpanFunc<char, TArg, TResult> parser, DecodingContext context, LengthFormat lengthFormat, Memory<byte> buffer, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to read from.
TArg argThe argument to be passed to parser
.
The parser of characters.
DecodingContext contextThe decoding context containing string characters encoding.
LengthFormat lengthFormatThe format of the string length (in bytes) encoded in the stream.
Memory<byte> bufferThe buffer that is allocated by the caller.
MemoryAllocator<char> allocatorThe allocator of internal buffer.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<TResult>The parsed value.
Type Parameters Name Description TArgThe type of the argument to be passed to parser
.
The type of the result.
Exceptions | Edit this page View Source ReadAllAsync(Stream, int, MemoryAllocator<byte>?, CancellationToken)Reads the stream sequentially.
Declarationpublic static IAsyncEnumerable<ReadOnlyMemory<byte>> ReadAllAsync(this Stream source, int bufferSize, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters Returns Exceptions | Edit this page View Source ReadAsync<T>(Stream, Memory<byte>, CancellationToken)
Parses the value encoded as a sequence of bytes.
Declarationpublic static ValueTask<T> ReadAsync<T>(this Stream stream, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryFormattable<T>
Parameters Type Name Description Stream stream
The stream to read from.
Memory<byte> bufferThe buffer allocated by the caller.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The parsed value.
Type Parameters Name Description TThe type of the result.
Exceptions | Edit this page View Source ReadBigEndianAsync<T>(Stream, Memory<byte>, CancellationToken)Reads integer encoded in big-endian format.
Declarationpublic static ValueTask<T> ReadBigEndianAsync<T>(this Stream stream, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description Stream stream
The stream to read from.
Memory<byte> bufferThe buffer allocated by the caller.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The integer value.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source ReadBlockAsync(Stream, LengthFormat, MemoryAllocator<byte>?, CancellationToken)Decodes the block of bytes asynchronously.
Declarationpublic static ValueTask<MemoryOwner<byte>> ReadBlockAsync(this Stream stream, LengthFormat lengthFormat, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to read from.
LengthFormat lengthFormatThe format of the block length encoded in the underlying stream.
MemoryAllocator<byte> allocatorThe memory allocator used to place the decoded block of bytes.
CancellationToken tokenThe token that can be used to cancel asynchronous operation.
Returns Exceptions | Edit this page View Source ReadExactlyAsync(Stream, long, int, MemoryAllocator<byte>?, CancellationToken)Reads exactly the specified amount of bytes as a sequence of chunks.
Declarationpublic static IAsyncEnumerable<ReadOnlyMemory<byte>> ReadExactlyAsync(this Stream stream, long length, int bufferSize, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to read from.
long lengthThe numbers of bytes to read.
int bufferSizeThe maximum size of chunks to be returned.
MemoryAllocator<byte> allocatorThe buffer allocator.
CancellationToken tokenThe token that can be used to cancel the enumeration.
Returns Exceptions | Edit this page View Source ReadLittleEndianAsync<T>(Stream, Memory<byte>, CancellationToken)Reads integer encoded in little-endian format.
Declarationpublic static ValueTask<T> ReadLittleEndianAsync<T>(this Stream stream, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description Stream stream
The stream to read from.
Memory<byte> bufferThe buffer allocated by the caller.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The integer value.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source ReadUtf8(Stream, Span<byte>, IBufferWriter<char>)Decodes null-terminated UTF-8 encoded string synchronously.
Declarationpublic static int ReadUtf8(this Stream stream, Span<byte> buffer, IBufferWriter<char> output)
Parameters Type Name Description Stream stream
The stream containing encoded string.
Span<byte> bufferThe buffer used to read from stream.
IBufferWriter<char> outputThe output buffer for decoded characters.
Returns Type Description intThe number of used bytes in buffer
.
Decodes null-terminated UTF-8 encoded string asynchronously.
Declarationpublic static ValueTask<int> ReadUtf8Async(this Stream stream, Memory<byte> buffer, IBufferWriter<char> output, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream containing encoded string.
Memory<byte> bufferThe buffer used to read from stream.
IBufferWriter<char> outputThe output buffer for decoded characters.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The number of used bytes in buffer
.
Decodes null-terminated UTF-8 encoded string asynchronously.
Declarationpublic static ValueTask<int> ReadUtf8Async<TArg>(this Stream stream, Memory<byte> bytesBuf, Memory<char> charsBuf, Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask> action, TArg arg, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream containing encoded string.
Memory<byte> bytesBufThe buffer used to read from stream.
Memory<char> charsBufThe buffer used to place decoded characters.
Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask> actionThe callback to be executed for each decoded portion of char data.
TArg argThe argument to be passed to action
.
The token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The number of used bytes in bytesBuf
.
The type of the argument to be passed to action
.
Decodes null-terminated UTF-8 encoded string synchronously.
Declarationpublic static int ReadUtf8<TArg>(this Stream stream, Span<byte> bytesBuf, Span<char> charsBuf, ReadOnlySpanAction<char, TArg> action, TArg arg)
Parameters Type Name Description Stream stream
The stream containing encoded string.
Span<byte> bytesBufThe buffer used to read from stream.
Span<char> charsBufThe buffer used to place decoded characters.
ReadOnlySpanAction<char, TArg> actionThe callback to be executed for each decoded portion of char data.
TArg argThe argument to be passed to action
.
The number of used bytes in bytesBuf
.
The type of the argument to be passed to action
.
Writes sequence of bytes to the underlying stream asynchronously.
Declarationpublic static ValueTask WriteAsync(this Stream stream, ReadOnlySequence<byte> sequence, CancellationToken token = default)
Parameters Returns Type Description ValueTask
The task representing asynchronous execution of this method.
Exceptions | Edit this page View Source WriteAsync(Stream, ReadOnlyMemory<byte>, LengthFormat, Memory<byte>, CancellationToken)Encodes the octet string asynchronously.
Declarationpublic static ValueTask WriteAsync(this Stream stream, ReadOnlyMemory<byte> value, LengthFormat lengthFormat, Memory<byte> buffer, CancellationToken token = default)
Parameters Type Name Description Stream stream
The stream to write into.
ReadOnlyMemory<byte> valueThe octet string to encode.
LengthFormat lengthFormatThe format of the octet string length that must be inserted before the payload.
Memory<byte> bufferThe buffer for internal I/O operations.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing asynchronous state of the operation.
Exceptions | Edit this page View Source WriteAsync<T>(Stream, T, Memory<byte>, CancellationToken)Encodes formattable value as a sequence of bytes.
Declarationpublic static ValueTask WriteAsync<T>(this Stream stream, T value, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryFormattable<T>
Parameters Type Name Description Stream stream
The stream to write into.
T valueThe type value to be written as string.
Memory<byte> bufferThe buffer to be used for characters encoding.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe type of formattable value.
Exceptions | Edit this page View Source WriteBigEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)Writes the integer to the stream in big-endian format.
Declarationpublic static ValueTask WriteBigEndianAsync<T>(this Stream stream, T value, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description Stream stream
The stream to write into.
T valueThe value to be written in big-endian format.
Memory<byte> bufferThe buffer to be used for characters encoding.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source WriteLittleEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)Writes the integer to the stream in little-endian format.
Declarationpublic static ValueTask WriteLittleEndianAsync<T>(this Stream stream, T value, Memory<byte> buffer, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description Stream stream
The stream to write into.
T valueThe value to be written in little-endian format.
Memory<byte> bufferThe buffer to be used for characters encoding.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe integer type.
ExceptionsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4