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
sequenceReadOnlySequence<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
bufferbyte[]When this method returns, contains the specified byte array with the values between
offsetand (offset+count- 1) replaced by the characters read from the current stream.offsetintThe zero-based byte offset in
bufferat which to begin storing data from the current stream.countintThe 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
bufferis null.- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentException
offsetsubtracted from the buffer length is less thancount.- ObjectDisposedException
The current stream instance is closed.
Read(Span<byte>)
public int Read(Span<byte> destination)
Parameters
Returns
ReadByte()
Reads a byte from the current stream.
public override int ReadByte()
Returns
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
bufferbyte[]An array of bytes. When this method returns, the buffer contains the specified byte array with the values between
offsetand (offset+count- 1) replaced by the bytes read from the current source.offsetintThe byte offset in
bufferat which to begin storing the data read from the current stream.countintThe number of bytes to be read from the current stream.
Exceptions
- EndOfStreamException
The end of the stream is reached before reading
countbytes.
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
bufferSpan<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
offsetlongThe new position within the stream. This is relative to the
locparameter, and can be positive or negative.locSeekOriginA 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
offsetis greater than MaxValue.- ArgumentException
There is an invalid SeekOrigin. -or-
offsetcaused 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
valuelongThe value at which to set the length.
Exceptions
- NotSupportedException
The current stream is not resizable and
valueis larger than the current capacity.-or- The current stream does not support writing.- ArgumentOutOfRangeException
valueis 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
bufferReadOnlySpan<byte>