A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://dotnet.github.io/dotNext/api/DotNext.IO.StreamExtensions.html below:

Class StreamExtensions | .NEXT

Class StreamExtensions

Represents high-level read/write methods for the stream.

Inheritance

StreamExtensions

Namespace: DotNext.IO Assembly: DotNext.IO.dll Syntax
public static class StreamExtensions
Methods | Edit this page View Source AsUnbufferedStream(SafeFileHandle, FileAccess)

Creates a stream for the specified file handle.

Declaration
public 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.

Declaration
public static Stream Combine(this IEnumerable<Stream> streams, bool leaveOpen = true)
Parameters Type Name Description IEnumerable<Stream> streams

A collection of streams.

bool leaveOpen

true to keep the wrapped streams alive when combined stream disposed; otherwise, false.

Returns Type Description Stream

An object that represents multiple streams as one logical stream.

Exceptions | Edit this page View Source Combine(Stream, ReadOnlySpan<Stream>)

Combines multiple readable streams.

Declaration
public 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.

Declaration
public static Stream Combine(this ReadOnlySpan<Stream> streams, bool leaveOpen = true)
Parameters Type Name Description ReadOnlySpan<Stream> streams

A collection of streams.

bool leaveOpen

true to keep the wrapped streams alive when combined stream disposed; otherwise, false.

Returns Type Description Stream

An 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.

Declaration
public 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> destination

The writer to which the contents of the current stream will be copied.

int bufferSize

The size, in bytes, of the buffer.

CancellationToken token

The token to monitor for cancellation requests.

Returns Type Description ValueTask

The 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.

Declaration
public 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> destination

The writer to which the contents of the current stream will be copied.

long count

The number of bytes to copy.

int bufferSize

The size, in bytes, of the buffer.

CancellationToken token

The token to monitor for cancellation requests.

Returns Type Description ValueTask

The 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.

Declaration
public 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 destination

The destination stream to write into.

long count

The number of bytes to copy.

Memory<byte> buffer

The buffer used to hold copied content temporarily.

CancellationToken token

The token that can be used to cancel this operation.

Returns Type Description ValueTask

The 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.

Declaration
public 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 destination

The destination stream to write into.

Memory<byte> buffer

The buffer used to hold copied content temporarily.

CancellationToken token

The token that can be used to cancel this operation.

Returns Type Description ValueTask

The 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.

Declaration
public 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 consumer

The destination stream to write into.

long count

The number of bytes to copy.

Memory<byte> buffer

The buffer used to hold copied content temporarily.

CancellationToken token

The token that can be used to cancel this operation.

Returns Type Description ValueTask

The task representing asynchronous execution of this method.

Type Parameters Name Description TConsumer

The 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.

Declaration
public 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 consumer

The destination stream to write into.

Memory<byte> buffer

The buffer used to hold copied content temporarily.

CancellationToken token

The token that can be used to cancel this operation.

Returns Type Description ValueTask

The task representing asynchronous execution of this method.

Type Parameters Name Description TConsumer

The 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.

Declaration
public 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 context

The text decoding context.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

Memory<byte> buffer

The buffer that is allocated by the caller.

MemoryAllocator<char> allocator

The allocator of the buffer of characters.

CancellationToken token

The 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.

Declaration
public 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 context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

Memory<char> charBuffer

The buffer of characters.

Memory<byte> byteBuffer

The buffer of bytes.

CancellationToken token

The 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.

Declaration
public 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> chars

The string to be encoded.

EncodingContext context

The encoding context.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

Memory<byte> buffer

The buffer allocated by the caller needed for characters encoding.

CancellationToken token

The 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.

Declaration
public 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 value

The type value to be written as string.

EncodingContext context

The context describing encoding of characters.

LengthFormat? lengthFormat

String length encoding format; or null to prevent encoding of string length.

Memory<byte> buffer

The buffer to be used for characters encoding.

string format

The format of the value.

IFormatProvider provider

The format provider.

MemoryAllocator<char> allocator

A memory allocator for internal buffer of chars.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Parameters Name Description T

The 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.

Declaration
public 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 value

The type value to be written as string.

LengthFormat? lengthFormat

String length encoding format.

Memory<byte> buffer

The buffer to be used for characters encoding.

string format

The format of the value.

IFormatProvider provider

The format provider.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<int>

The number of written bytes.

Type Parameters Name Description T

The 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.

Declaration
public 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 lengthFormat

The format of the string length (in bytes) encoded in the stream.

Memory<byte> buffer

The buffer that is allocated by the caller.

NumberStyles style

A combination of number styles.

IFormatProvider provider

Culture-specific formatting information.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<T>

The result of parsing.

Type Parameters Name Description T

The 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.

Declaration
public 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 lengthFormat

The format of the string length (in bytes) encoded in the stream.

Memory<byte> buffer

The buffer that is allocated by the caller.

IFormatProvider provider

Culture-specific formatting information.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<T>

The result of parsing.

Type Parameters Name Description T

The 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.

Declaration
public 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 arg

The argument to be passed to parser.

ReadOnlySpanFunc<char, TArg, TResult> parser

The parser of characters.

DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length (in bytes) encoded in the stream.

Memory<byte> buffer

The buffer that is allocated by the caller.

MemoryAllocator<char> allocator

The allocator of internal buffer.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<TResult>

The parsed value.

Type Parameters Name Description TArg

The type of the argument to be passed to parser.

TResult

The type of the result.

Exceptions | Edit this page View Source ReadAllAsync(Stream, int, MemoryAllocator<byte>?, CancellationToken)

Reads the stream sequentially.

Declaration
public 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.

Declaration
public 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> buffer

The buffer allocated by the caller.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<T>

The parsed value.

Type Parameters Name Description T

The type of the result.

Exceptions | Edit this page View Source ReadBigEndianAsync<T>(Stream, Memory<byte>, CancellationToken)

Reads integer encoded in big-endian format.

Declaration
public 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> buffer

The buffer allocated by the caller.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<T>

The integer value.

Type Parameters Name Description T

The integer type.

Exceptions | Edit this page View Source ReadBlockAsync(Stream, LengthFormat, MemoryAllocator<byte>?, CancellationToken)

Decodes the block of bytes asynchronously.

Declaration
public 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 lengthFormat

The format of the block length encoded in the underlying stream.

MemoryAllocator<byte> allocator

The memory allocator used to place the decoded block of bytes.

CancellationToken token

The 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.

Declaration
public 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 length

The numbers of bytes to read.

int bufferSize

The maximum size of chunks to be returned.

MemoryAllocator<byte> allocator

The buffer allocator.

CancellationToken token

The 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.

Declaration
public 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> buffer

The buffer allocated by the caller.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<T>

The integer value.

Type Parameters Name Description T

The integer type.

Exceptions | Edit this page View Source ReadUtf8(Stream, Span<byte>, IBufferWriter<char>)

Decodes null-terminated UTF-8 encoded string synchronously.

Declaration
public 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> buffer

The buffer used to read from stream.

IBufferWriter<char> output

The output buffer for decoded characters.

Returns Type Description int

The number of used bytes in buffer.

Exceptions | Edit this page View Source ReadUtf8Async(Stream, Memory<byte>, IBufferWriter<char>, CancellationToken)

Decodes null-terminated UTF-8 encoded string asynchronously.

Declaration
public 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> buffer

The buffer used to read from stream.

IBufferWriter<char> output

The output buffer for decoded characters.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<int>

The number of used bytes in buffer.

Exceptions | Edit this page View Source ReadUtf8Async<TArg>(Stream, Memory<byte>, Memory<char>, Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask>, TArg, CancellationToken)

Decodes null-terminated UTF-8 encoded string asynchronously.

Declaration
public 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> bytesBuf

The buffer used to read from stream.

Memory<char> charsBuf

The buffer used to place decoded characters.

Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask> action

The callback to be executed for each decoded portion of char data.

TArg arg

The argument to be passed to action.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask<int>

The number of used bytes in bytesBuf.

Type Parameters Name Description TArg

The type of the argument to be passed to action.

Exceptions | Edit this page View Source ReadUtf8<TArg>(Stream, Span<byte>, Span<char>, ReadOnlySpanAction<char, TArg>, TArg)

Decodes null-terminated UTF-8 encoded string synchronously.

Declaration
public 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> bytesBuf

The buffer used to read from stream.

Span<char> charsBuf

The buffer used to place decoded characters.

ReadOnlySpanAction<char, TArg> action

The callback to be executed for each decoded portion of char data.

TArg arg

The argument to be passed to action.

Returns Type Description int

The number of used bytes in bytesBuf.

Type Parameters Name Description TArg

The type of the argument to be passed to action.

Exceptions | Edit this page View Source WriteAsync(Stream, ReadOnlySequence<byte>, CancellationToken)

Writes sequence of bytes to the underlying stream asynchronously.

Declaration
public 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.

Declaration
public 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> value

The octet string to encode.

LengthFormat lengthFormat

The format of the octet string length that must be inserted before the payload.

Memory<byte> buffer

The buffer for internal I/O operations.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask

The 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.

Declaration
public 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 value

The type value to be written as string.

Memory<byte> buffer

The buffer to be used for characters encoding.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask

The task representing state of asynchronous execution.

Type Parameters Name Description T

The 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.

Declaration
public 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 value

The value to be written in big-endian format.

Memory<byte> buffer

The buffer to be used for characters encoding.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask

The task representing state of asynchronous execution.

Type Parameters Name Description T

The 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.

Declaration
public 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 value

The value to be written in little-endian format.

Memory<byte> buffer

The buffer to be used for characters encoding.

CancellationToken token

The token that can be used to cancel the operation.

Returns Type Description ValueTask

The task representing state of asynchronous execution.

Type Parameters Name Description T

The integer type.

Exceptions

RetroSearch 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