Class PipeExtensions
Represents extension method for parsing data stored in pipe.
Inherited Members
Namespace: DotNext.IO.Pipelines
Assembly: DotNext.IO.dll
Syntax
public static class PipeExtensions
  Methods
| Edit this page View SourceCopyFromAsync(PipeWriter, Stream, long, CancellationToken)
Copies the specified number of bytes from source stream.
Declaration
public static ValueTask CopyFromAsync(this PipeWriter destination, Stream source, long count, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeWriter | destination | The pipe to write into.  | 
      
| Stream | source | The source stream.  | 
      
| long | count | The number of bytes to be copied.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of this method.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
| ArgumentNullException | 
  | 
      
| EndOfStreamException | 
  | 
      
CopyToAsync<TConsumer>(PipeReader, TConsumer, long, CancellationToken)
Reads the entire content using the specified consumer.
Declaration
public static ValueTask CopyToAsync<TConsumer>(this PipeReader reader, TConsumer consumer, long count, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe to read from.  | 
      
| TConsumer | consumer | The content reader.  | 
      
| long | count | The number of bytes to copy.  | 
      
| CancellationToken | token | The token that can be used to cancel operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of this method.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| TConsumer | The type of the consumer.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
CopyToAsync<TConsumer>(PipeReader, TConsumer, CancellationToken)
Reads the entire content using the specified consumer.
Declaration
public static ValueTask CopyToAsync<TConsumer>(this PipeReader reader, TConsumer consumer, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe to read from.  | 
      
| TConsumer | consumer | The content reader.  | 
      
| CancellationToken | token | The token that can be used to cancel operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of this method.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| TConsumer | The type of the consumer.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
DecodeAsync(PipeReader, DecodingContext, LengthFormat, MemoryAllocator<char>?, CancellationToken)
Decodes string asynchronously from pipe.
Declaration
public static ValueTask<MemoryOwner<char>> DecodeAsync(this PipeReader reader, DecodingContext context, LengthFormat lengthFormat, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| DecodingContext | context | The text decoding context.  | 
      
| LengthFormat | lengthFormat | Represents string length encoding format.  | 
      
| MemoryAllocator<char> | allocator | The allocator of the buffer of characters.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask<MemoryOwner<char>> | The buffer of characters.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| EndOfStreamException | 
  | 
      
| OperationCanceledException | The operation has been canceled.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
DecodeAsync(PipeReader, DecodingContext, LengthFormat, Memory<char>, CancellationToken)
Decodes the sequence of characters.
Declaration
public static IAsyncEnumerable<ReadOnlyMemory<char>> DecodeAsync(this PipeReader reader, DecodingContext context, LengthFormat lengthFormat, Memory<char> buffer, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| DecodingContext | context | The decoding context containing string characters encoding.  | 
      
| LengthFormat | lengthFormat | The format of the string length encoded in the stream.  | 
      
| Memory<char> | buffer | The buffer of characters.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| IAsyncEnumerable<ReadOnlyMemory<char>> | The enumerator of characters.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
ParseAsync<T>(PipeReader, LengthFormat, NumberStyles, IFormatProvider?, CancellationToken)
Parses the numeric value from UTF-8 encoded characters.
Declaration
public static ValueTask<T> ParseAsync<T>(this PipeReader reader, LengthFormat lengthFormat, NumberStyles style, IFormatProvider? provider = null, CancellationToken token = default) where T : INumberBase<T>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| LengthFormat | lengthFormat | The format of the string length (in bytes) encoded in the stream.  | 
      
| 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
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
ParseAsync<T>(PipeReader, LengthFormat, IFormatProvider?, CancellationToken)
Parses the sequence of characters encoded as UTF-8.
Declaration
public static ValueTask<T> ParseAsync<T>(this PipeReader reader, LengthFormat lengthFormat, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanParsable<T>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| LengthFormat | lengthFormat | The format of the string length (in bytes) encoded in the stream.  | 
      
| 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
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
ParseAsync<TArg, TResult>(PipeReader, TArg, ReadOnlySpanFunc<char, TArg, TResult>, DecodingContext, LengthFormat, MemoryAllocator<char>?, CancellationToken)
Parses the sequence of characters.
Declaration
public static ValueTask<TResult> ParseAsync<TArg, TResult>(this PipeReader reader, TArg arg, ReadOnlySpanFunc<char, TArg, TResult> parser, DecodingContext context, LengthFormat lengthFormat, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| TArg | arg | The argument to be passed to   | 
      
| 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.  | 
      
| 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   | 
      
| TResult | The type of the result.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
ReadAllAsync(PipeReader, CancellationToken)
Reads all chunks of data from the pipe.
Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> ReadAllAsync(this PipeReader reader, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| IAsyncEnumerable<ReadOnlyMemory<byte>> | A sequence of data chunks.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
ReadAsync(PipeReader, LengthFormat, MemoryAllocator<byte>?, CancellationToken)
Reads length-prefixed block of bytes.
Declaration
public static ValueTask<MemoryOwner<byte>> ReadAsync(this PipeReader reader, LengthFormat lengthFormat, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| LengthFormat | lengthFormat | The format of the block length encoded in the underlying pipe.  | 
      
| MemoryAllocator<byte> | allocator | The memory allocator used to place the decoded block of bytes.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask<MemoryOwner<byte>> | The decoded block of bytes.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | Reader doesn't have enough data.  | 
      
ReadAsync(PipeReader, Memory<byte>, CancellationToken)
Reads the block of memory.
Declaration
public static ValueTask<int> ReadAsync(this PipeReader reader, Memory<byte> output, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| Memory<byte> | output | The block of memory to fill from the pipe.  | 
      
| CancellationToken | token | The token that can be used to cancel operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask<int> | The actual number of copied bytes.  | 
      
ReadAsync<T>(PipeReader, CancellationToken)
Decodes the value of binary formattable type.
Declaration
public static ValueTask<T> ReadAsync<T>(this PipeReader reader, CancellationToken token = default) where T : IBinaryFormattable<T>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask<T> | The decoded value.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the result.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
ReadAtLeastAsync(PipeReader, Memory<byte>, int, CancellationToken)
Reads at least the specified number of bytes.
Declaration
public static ValueTask<int> ReadAtLeastAsync(this PipeReader reader, Memory<byte> destination, int minimumSize, CancellationToken token)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| Memory<byte> | destination | The buffer to write into.  | 
      
| int | minimumSize | The minimum number of bytes to read.  | 
      
| CancellationToken | token | The token that can be used to cancel operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask<int> | The actual number of bytes written to   | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | Reader doesn't have enough data.  | 
      
ReadBigEndianAsync<T>(PipeReader, CancellationToken)
Reads integer encoded in big-endian format.
Declaration
public static ValueTask<T> ReadBigEndianAsync<T>(this PipeReader reader, CancellationToken token = default) where T : IBinaryInteger<T>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| 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
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
ReadExactlyAsync(PipeReader, long, CancellationToken)
Reads exactly the specified amount of bytes as a sequence of chunks.
Declaration
public static IAsyncEnumerable<ReadOnlyMemory<byte>> ReadExactlyAsync(this PipeReader reader, long length, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| long | length | The numbers of bytes to read.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| IAsyncEnumerable<ReadOnlyMemory<byte>> | A collection of chunks.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| EndOfStreamException | Reader doesn't have enough data to skip.  | 
      
| OperationCanceledException | The operation has been canceled.  | 
      
| ArgumentOutOfRangeException | 
  | 
      
ReadExactlyAsync(PipeReader, Memory<byte>, CancellationToken)
Reads the block of memory.
Declaration
public static ValueTask ReadExactlyAsync(this PipeReader reader, Memory<byte> output, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| Memory<byte> | output | The block of memory to fill from the pipe.  | 
      
| CancellationToken | token | The token that can be used to cancel operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous state of the operation.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | Reader doesn't have enough data.  | 
      
ReadLittleEndianAsync<T>(PipeReader, CancellationToken)
Reads integer encoded in little-endian format.
Declaration
public static ValueTask<T> ReadLittleEndianAsync<T>(this PipeReader reader, CancellationToken token = default) where T : IBinaryInteger<T>
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| 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
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value.  | 
      
ReadUtf8Async(PipeReader, IBufferWriter<char>, CancellationToken)
Decodes null-terminated UTF-8 encoded string.
Declaration
public static ValueTask ReadUtf8Async(this PipeReader reader, IBufferWriter<char> output, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| 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 | The task representing asynchronous execution of this method.  | 
      
Remarks
This method returns when writer side completed or null char reached.
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | |
| OperationCanceledException | The operation has been canceled.  | 
      
SkipAsync(PipeReader, long, CancellationToken)
Drops the specified number of bytes from the pipe.
Declaration
public static ValueTask SkipAsync(this PipeReader reader, long length, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| long | length | The number of bytes to skip.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of this method.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
| OperationCanceledException | The operation has been canceled.  | 
      
| EndOfStreamException | Reader doesn't have enough data to skip.  | 
      
TryReadExactly(PipeReader, long, out ReadResult)
Attempts to read block of data synchronously.
Declaration
public static bool TryReadExactly(this PipeReader reader, long length, out ReadResult result)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeReader | reader | The pipe reader.  | 
      
| long | length | The length of the block to consume, in bytes.  | 
      
| ReadResult | result | The requested block of data which length is equal to   | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if the block of requested length is obtained successfully; otherwise, false.  | 
      
Remarks
This method doesn't advance the reader position.
WriteAsync(PipeWriter, ReadOnlySequence<byte>, CancellationToken)
Writes sequence of bytes to the underlying stream asynchronously.
Declaration
public static ValueTask WriteAsync(this PipeWriter writer, ReadOnlySequence<byte> sequence, CancellationToken token = default)
  Parameters
| Type | Name | Description | 
|---|---|---|
| PipeWriter | writer | The pipe to write into.  | 
      
| ReadOnlySequence<byte> | sequence | The sequence of bytes.  | 
      
| CancellationToken | token | The token that can be used to cancel the operation.  | 
      
Returns
| Type | Description | 
|---|---|
| ValueTask | The task representing asynchronous execution of this method.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| OperationCanceledException | The operation has been canceled.  |