Show / Hide Table of Contents

Class StreamSource

Represents Stream factory methods.

Inheritance
object
StreamSource
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.IO
Assembly: DotNext.dll
Syntax
public static class StreamSource

Methods

View Source

Create(SparseBufferWriter<byte>, bool)

Creates a stream over sparse memory.

Declaration
public static Stream Create(SparseBufferWriter<byte> writer, bool writable)
Parameters
Type Name Description
SparseBufferWriter<byte> writer

Sparse memory buffer.

bool writable

true to create writable stream; false to create read-only stream.

Returns
Type Description
Stream

Sparse memory stream.

View Source

Create(ArraySegment<byte>, bool)

Converts segment of an array to the stream.

Declaration
public static Stream Create(ArraySegment<byte> segment, bool writable)
Parameters
Type Name Description
ArraySegment<byte> segment

The array of bytes.

bool writable

Determines whether the stream supports writing.

Returns
Type Description
Stream

The stream representing the array segment.

View Source

Create(ReadOnlySequence<byte>)

Converts read-only sequence of bytes to a read-only stream.

Declaration
public static Stream Create(ReadOnlySequence<byte> sequence)
Parameters
Type Name Description
ReadOnlySequence<byte> sequence

The sequence of bytes.

Returns
Type Description
Stream

The stream over sequence of bytes.

View Source

Create(ReadOnlyMemory<byte>)

Converts read-only memory to a read-only stream.

Declaration
public static Stream Create(ReadOnlyMemory<byte> memory)
Parameters
Type Name Description
ReadOnlyMemory<byte> memory

The read-only memory.

Returns
Type Description
Stream

The stream over memory of bytes.

View Source

CreateAsyncReadOnly<TArg>(Func<Memory<byte>, TArg, CancellationToken, ValueTask<int>>, TArg)

Returns read-only asynchronous stream that wraps the provided delegate for reading data.

Declaration
public static Stream CreateAsyncReadOnly<TArg>(Func<Memory<byte>, TArg, CancellationToken, ValueTask<int>> reader, TArg arg)
Parameters
Type Name Description
Func<Memory<byte>, TArg, CancellationToken, ValueTask<int>> reader

The callback to be called for each read.

TArg arg

The arg to be passed to the callback.

Returns
Type Description
Stream

A readable stream wrapping the callback.

Type Parameters
Name Description
TArg

The type of the argument to be passed to the delegate.

Exceptions
Type Condition
ArgumentNullException

reader is null.

View Source

CreateAsyncWritable<TArg>(Func<ReadOnlyMemory<byte>, TArg, CancellationToken, ValueTask>, TArg, Action<TArg>?, Func<TArg, CancellationToken, Task>?)

Returns writable stream that wraps the provided delegate for writing data.

Declaration
public static Stream CreateAsyncWritable<TArg>(Func<ReadOnlyMemory<byte>, TArg, CancellationToken, ValueTask> writer, TArg arg, Action<TArg>? flush = null, Func<TArg, CancellationToken, Task>? flushAsync = null)
Parameters
Type Name Description
Func<ReadOnlyMemory<byte>, TArg, CancellationToken, ValueTask> writer

The callback to be called for each write.

TArg arg

The arg to be passed to the callback.

Action<TArg> flush

Optional synchronous flush action.

Func<TArg, CancellationToken, Task> flushAsync

Optional asynchronous flush action.

Returns
Type Description
Stream

A writable stream wrapping the callback.

Type Parameters
Name Description
TArg

The type of the object that represents the state.

Exceptions
Type Condition
ArgumentNullException

writer is null.

View Source

CreateAsyncWritable<TOutput>(TOutput)

Returns writable asynchronous stream.

Declaration
public static Stream CreateAsyncWritable<TOutput>(TOutput output) where TOutput : notnull, ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>, IFlushable
Parameters
Type Name Description
TOutput output

The consumer of the stream content.

Returns
Type Description
Stream

The stream wrapping TOutput.

Type Parameters
Name Description
TOutput

The type of the consumer.

View Source

CreateShared(ReadOnlySequence<byte>, bool)

Gets read-only stream that can be shared across async flows or threads for independent reads.

Declaration
public static Stream CreateShared(ReadOnlySequence<byte> sequence, bool compatWithAsync = true)
Parameters
Type Name Description
ReadOnlySequence<byte> sequence

The sequence of bytes.

bool compatWithAsync

true to create a stream than can be shared across async flows and different threads; false to create a stream that is safe to share between different threads only.

Returns
Type Description
Stream

The stream over sequence of bytes.

Remarks

You need to set a position explicitly before using stream for each parallel async flow. SetLength(long) is not supported to avoid different views of the same stream.

View Source

CreateWritable<TArg>(ReadOnlySpanAction<byte, TArg>, TArg, Action<TArg>?, Func<TArg, CancellationToken, Task>?)

Returns writable stream that wraps the provided delegate for writing data.

Declaration
public static Stream CreateWritable<TArg>(ReadOnlySpanAction<byte, TArg> writer, TArg arg, Action<TArg>? flush = null, Func<TArg, CancellationToken, Task>? flushAsync = null)
Parameters
Type Name Description
ReadOnlySpanAction<byte, TArg> writer

The callback that is called automatically.

TArg arg

The arg to be passed to the callback.

Action<TArg> flush

Optional synchronous flush action.

Func<TArg, CancellationToken, Task> flushAsync

Optional asynchronous flush action.

Returns
Type Description
Stream

The writable stream wrapping the callback.

Type Parameters
Name Description
TArg

The type of the object that represents the state.

View Source

CreateWritable<TOutput>(TOutput)

Returns writable synchronous stream.

Declaration
public static Stream CreateWritable<TOutput>(TOutput output) where TOutput : notnull, IFlushable, IConsumer<ReadOnlySpan<byte>>
Parameters
Type Name Description
TOutput output

The consumer of the stream content.

Returns
Type Description
Stream

The stream wrapping TOutput.

Type Parameters
Name Description
TOutput

The type of the consumer.

View Source

CreateWritable<TWriter>(TWriter, Action<TWriter>?, Func<TWriter, CancellationToken, Task>?)

Returns writable stream associated with the buffer writer.

Declaration
public static Stream CreateWritable<TWriter>(TWriter writer, Action<TWriter>? flush, Func<TWriter, CancellationToken, Task>? flushAsync) where TWriter : class, IBufferWriter<byte>
Parameters
Type Name Description
TWriter writer

The writer to be wrapped by the stream.

Action<TWriter> flush

Optional synchronous flush action.

Func<TWriter, CancellationToken, Task> flushAsync

Optional asynchronous flush action.

Returns
Type Description
Stream

The writable stream wrapping buffer writer.

Type Parameters
Name Description
TWriter

The type of the writer.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾