Table of Contents

Class ReadOnlySequenceMemoryStream

Namespace
CryptoHives.Foundation.Memory.Buffers
Assembly
CryptoHives.Foundation.Memory.dll

Class to create a read only MemoryStream which uses a ReadOnlySequence<T> as the buffer source.

public sealed class ReadOnlySequenceMemoryStream : MemoryStream, IDisposable
Inheritance
ReadOnlySequenceMemoryStream
Implements
Inherited Members

Constructors

ReadOnlySequenceMemoryStream(ReadOnlySequence<byte>)

Initializes a new instance of the ReadOnlySequenceMemoryStream class.

public ReadOnlySequenceMemoryStream(ReadOnlySequence<byte> sequence)

Parameters

sequence ReadOnlySequence<byte>

Properties

CanRead

Gets a value indicating whether the current stream supports reading.

public override bool CanRead { get; }

Property Value

bool

true if the stream is open.

CanSeek

Gets a value indicating whether the current stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

true if the stream is open.

CanWrite

Gets a value indicating whether the current stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

true if the stream supports writing; otherwise, false.

Length

Gets the length of the stream in bytes.

public override long Length { get; }

Property Value

long

The length of the stream in bytes.

Exceptions

ObjectDisposedException

The stream is closed.

Position

Gets or sets the current position within the stream.

public override long Position { get; set; }

Property Value

long

The current position within the stream.

Exceptions

ArgumentOutOfRangeException

The position is set to a negative value or a value greater than MaxValue.

ObjectDisposedException

The stream is closed.

Methods

Flush()

Overrides the Flush() method so that no action is performed.

public override void Flush()

Read(byte[], int, int)

Reads a block of bytes from the current stream and writes the data to a buffer.

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the characters read from the current stream.

offset int

The zero-based byte offset in buffer at which to begin storing data from the current stream.

count int

The maximum number of bytes to read.

Returns

int

The total number of bytes written into the buffer. This can be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached before any bytes are read.

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

offset subtracted from the buffer length is less than count.

ObjectDisposedException

The current stream instance is closed.

Read(Span<byte>)

public int Read(Span<byte> destination)

Parameters

destination Span<byte>

Returns

int

ReadByte()

Reads a byte from the current stream.

public override int ReadByte()

Returns

int

The byte cast to a int, or -1 if the end of the stream has been reached.

Exceptions

ObjectDisposedException

The current stream instance is closed.

ReadExactly(byte[], int, int)

Reads count bytes from the current stream and advances the position within the stream.

public void ReadExactly(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

offset int

The byte offset in buffer at which to begin storing the data read from the current stream.

count int

The number of bytes to be read from the current stream.

Exceptions

EndOfStreamException

The end of the stream is reached before reading count bytes.

ReadExactly(Span<byte>)

Reads bytes from the current stream and advances the position within the stream until the buffer is filled.

public void ReadExactly(Span<byte> buffer)

Parameters

buffer Span<byte>

A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current stream.

Exceptions

EndOfStreamException

The end of the stream is reached before filling the buffer.

Seek(long, SeekOrigin)

Sets the position within the current stream to the specified value.

public override long Seek(long offset, SeekOrigin loc)

Parameters

offset long

The new position within the stream. This is relative to the loc parameter, and can be positive or negative.

loc SeekOrigin

A value of type SeekOrigin, which acts as the seek reference point.

Returns

long

The new position within the stream, calculated by combining the initial reference point and the offset.

Exceptions

IOException

Seeking is attempted before the beginning of the stream.

ArgumentOutOfRangeException

offset is greater than MaxValue.

ArgumentException

There is an invalid SeekOrigin. -or-offset caused an arithmetic overflow.

ObjectDisposedException

The current stream instance is closed.

SetLength(long)

Sets the length of the current stream to the specified value.

public override void SetLength(long value)

Parameters

value long

The value at which to set the length.

Exceptions

NotSupportedException

The current stream is not resizable and value is larger than the current capacity.-or- The current stream does not support writing.

ArgumentOutOfRangeException

value is negative or is greater than the maximum length of the MemoryStream, where the maximum length is(MaxValue - origin), and origin is the index into the underlying buffer at which the stream starts.

ToArray()

Writes the stream contents to a byte array, regardless of the Position property.

public override byte[] ToArray()

Returns

byte[]

A new byte array.

Write(ReadOnlySpan<byte>)

public void Write(ReadOnlySpan<byte> buffer)

Parameters

buffer ReadOnlySpan<byte>