Class MemorySegmentStream
Represents a stream wrapper over the memory block.
Inherited Members
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public sealed class MemorySegmentStream : ModernStream, IAsyncDisposable, IDisposable, IFlushable
Constructors
| Edit this page View SourceMemorySegmentStream(Memory<byte>)
Represents a stream wrapper over the memory block.
Declaration
public MemorySegmentStream(Memory<byte> data)
Parameters
| Type | Name | Description |
|---|---|---|
| Memory<byte> | data | The mutable memory block. |
Properties
| Edit this page View SourceCanRead
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceCanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceCanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceConsumedSpan
Gets the consumed part of the data.
Declaration
public Span<byte> ConsumedSpan { get; }
Property Value
| Type | Description |
|---|---|
| Span<byte> |
Length
When overridden in a derived class, gets the length in bytes of the stream.
Declaration
public override long Length { get; }
Property Value
| Type | Description |
|---|---|
| long | A long value representing the length of the stream in bytes. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | A class derived from |
| ObjectDisposedException | Methods were called after the stream was closed. |
Position
When overridden in a derived class, gets or sets the position within the current stream.
Declaration
public override long Position { get; set; }
Property Value
| Type | Description |
|---|---|
| long | The current position within the stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| IOException | An I/O error occurs. |
| NotSupportedException | The stream does not support seeking. |
| ObjectDisposedException | Methods were called after the stream was closed. |
RemainingSpan
Gets the remaining part of the data.
Declaration
public Span<byte> RemainingSpan { get; }
Property Value
| Type | Description |
|---|---|
| Span<byte> |
SkipOnOverflow
Gets or sets a value indicating that Write(ReadOnlySpan<byte>) and WriteAsync(ReadOnlyMemory<byte>, CancellationToken) must throw IOException if the caller is trying to write past to the end of the underlying buffer.
Declaration
public bool SkipOnOverflow { get; init; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
The default value is false.
Methods
| Edit this page View SourceFlush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
Overrides
Exceptions
| Type | Condition |
|---|---|
| IOException | An I/O error occurs. |
FlushAsync(CancellationToken)
Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
Declaration
public override Task FlushAsync(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous flush operation. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | The stream has been disposed. |
Read(Span<byte>)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declaration
public override int Read(Span<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<byte> | buffer | A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source. |
Returns
| Type | Description |
|---|---|
| int | The total number of bytes read into the buffer. This can be less than the size of the buffer if that many bytes are not currently available, or zero (0) if the buffer's length is zero or the end of the stream has been reached. |
Overrides
| Edit this page View SourceReadAsync(Memory<byte>, CancellationToken)
Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Declaration
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Memory<byte> | buffer | The region of memory to write the data into. |
| CancellationToken | token |
Returns
| Type | Description |
|---|---|
| ValueTask<int> | A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into the buffer. The result value can be less than the length of the buffer if that many bytes are not currently available, or it can be 0 (zero) if the length of the buffer is 0 or if the end of the stream has been reached. |
Overrides
| Edit this page View SourceSeek(long, SeekOrigin)
When overridden in a derived class, sets the position within the current stream.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
| Type | Name | Description |
|---|---|---|
| long | offset | A byte offset relative to the |
| SeekOrigin | origin | A value of type SeekOrigin indicating the reference point used to obtain the new position. |
Returns
| Type | Description |
|---|---|
| long | The new position within the current stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| IOException | An I/O error occurs. |
| NotSupportedException | The stream does not support seeking, such as if the stream is constructed from a pipe or console output. |
| ObjectDisposedException | Methods were called after the stream was closed. |
SetLength(long)
When overridden in a derived class, sets the length of the current stream.
Declaration
public override void SetLength(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The desired length of the current stream in bytes. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| IOException | An I/O error occurs. |
| NotSupportedException | The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. |
| ObjectDisposedException | Methods were called after the stream was closed. |
Write(ReadOnlySpan<byte>)
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
Declaration
public override void Write(ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | buffer | A region of memory. This method copies the contents of this region to the current stream. |
Overrides
| Edit this page View SourceWriteAsync(ReadOnlyMemory<byte>, CancellationToken)
Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
Declaration
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyMemory<byte> | buffer | The region of memory to write data from. |
| CancellationToken | token |
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the asynchronous write operation. |