Show / Hide Table of Contents

Class RandomAccessStream

Represents a stream over the storage that supports random access.

Inheritance
object
MarshalByRefObject
Stream
ModernStream
RandomAccessStream
Implements
IAsyncDisposable
IDisposable
IFlushable
IValueTaskSource
IValueTaskSource<int>
Inherited Members
ModernStream.Read(byte[], int, int)
ModernStream.ReadAsync(byte[], int, int, CancellationToken)
ModernStream.BeginRead(byte[], int, int, AsyncCallback, object)
ModernStream.EndRead(IAsyncResult)
ModernStream.ReadByte()
ModernStream.Write(byte[], int, int)
ModernStream.WriteByte(byte)
ModernStream.WriteAsync(byte[], int, int, CancellationToken)
ModernStream.BeginWrite(byte[], int, int, AsyncCallback, object)
ModernStream.EndWrite(IAsyncResult)
Stream.Null
Stream.Close()
Stream.CopyTo(Stream)
Stream.CopyTo(Stream, int)
Stream.CopyToAsync(Stream)
Stream.CopyToAsync(Stream, int)
Stream.CopyToAsync(Stream, int, CancellationToken)
Stream.CopyToAsync(Stream, CancellationToken)
Stream.CreateWaitHandle()
Stream.Dispose()
Stream.DisposeAsync()
Stream.Flush()
Stream.FlushAsync()
Stream.FlushAsync(CancellationToken)
Stream.ObjectInvariant()
Stream.ReadAsync(byte[], int, int)
Stream.ReadAtLeast(Span<byte>, int, bool)
Stream.ReadAtLeastAsync(Memory<byte>, int, bool, CancellationToken)
Stream.ReadExactly(byte[], int, int)
Stream.ReadExactly(Span<byte>)
Stream.ReadExactlyAsync(byte[], int, int, CancellationToken)
Stream.ReadExactlyAsync(Memory<byte>, CancellationToken)
Stream.SetLength(long)
Stream.Synchronized(Stream)
Stream.ValidateBufferArguments(byte[], int, int)
Stream.ValidateCopyToArguments(Stream, int)
Stream.WriteAsync(byte[], int, int)
Stream.CanRead
Stream.CanTimeout
Stream.CanWrite
Stream.Length
Stream.ReadTimeout
Stream.WriteTimeout
MarshalByRefObject.GetLifetimeService()
MarshalByRefObject.InitializeLifetimeService()
MarshalByRefObject.MemberwiseClone(bool)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public abstract class RandomAccessStream : ModernStream, IAsyncDisposable, IDisposable, IFlushable, IValueTaskSource, IValueTaskSource<int>

Properties

| Edit this page View Source

CanSeek

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

true if the stream supports seeking; otherwise, false.

Overrides
Stream.CanSeek
| Edit this page View Source

Position

When overridden in a derived class, gets or sets the position within the current stream.

Declaration
public override sealed long Position { get; set; }
Property Value
Type Description
long

The current position within the stream.

Overrides
Stream.Position
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.

Methods

| Edit this page View Source

Dispose(bool)

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Overrides
Stream.Dispose(bool)
| Edit this page View Source

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 sealed 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
ModernStream.Read(Span<byte>)
| Edit this page View Source

Read(Span<byte>, long)

Reads bytes to the specified buffer.

Declaration
protected abstract int Read(Span<byte> buffer, long offset)
Parameters
Type Name Description
Span<byte> buffer

The buffer to be modified.

long offset

The offset within the underlying data storage.

Returns
Type Description
int

The number of bytes read.

| Edit this page View Source

ReadAsync(Memory<byte>, long, CancellationToken)

Reads bytes to the specified buffer.

Declaration
protected abstract ValueTask<int> ReadAsync(Memory<byte> buffer, long offset, CancellationToken token)
Parameters
Type Name Description
Memory<byte> buffer

The buffer to be modified.

long offset

The offset within the underlying data storage.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<int>

The number of bytes read.

| Edit this page View Source

ReadAsync(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 sealed 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
ModernStream.ReadAsync(Memory<byte>, CancellationToken)
| Edit this page View Source

Seek(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 origin parameter.

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
Stream.Seek(long, SeekOrigin)
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.

| Edit this page View Source

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 sealed 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
ModernStream.Write(ReadOnlySpan<byte>)
| Edit this page View Source

Write(ReadOnlySpan<byte>, long)

Writes the bytes at the specified offset.

Declaration
protected abstract void Write(ReadOnlySpan<byte> buffer, long offset)
Parameters
Type Name Description
ReadOnlySpan<byte> buffer

The buffer to write.

long offset

The offset within the underlying data storage.

| Edit this page View Source

WriteAsync(ReadOnlyMemory<byte>, long, CancellationToken)

Writes the bytes at the specified offset.

Declaration
protected abstract ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, long offset, CancellationToken token)
Parameters
Type Name Description
ReadOnlyMemory<byte> buffer

The buffer to write.

long offset

The offset within the underlying data storage.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous operation.

| Edit this page View Source

WriteAsync(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 sealed 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.

Overrides
ModernStream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)

Implements

IAsyncDisposable
IDisposable
IFlushable
IValueTaskSource
IValueTaskSource<TResult>

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
StreamExtensions.Combine(Stream, ReadOnlySpan<Stream>)
StreamExtensions.CopyToAsync(Stream, IBufferWriter<byte>, int, CancellationToken)
StreamExtensions.CopyToAsync(Stream, IBufferWriter<byte>, long, int, CancellationToken)
StreamExtensions.CopyToAsync(Stream, Stream, long, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync(Stream, Stream, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync<TConsumer>(Stream, TConsumer, long, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync<TConsumer>(Stream, TConsumer, Memory<byte>, CancellationToken)
StreamExtensions.DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<char>, Memory<byte>, CancellationToken)
StreamExtensions.EncodeAsync(Stream, ReadOnlyMemory<char>, EncodingContext, LengthFormat?, Memory<byte>, CancellationToken)
StreamExtensions.FormatAsync<T>(Stream, T, EncodingContext, LengthFormat?, Memory<byte>, string?, IFormatProvider?, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.FormatAsync<T>(Stream, T, LengthFormat?, Memory<byte>, string?, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<T>(Stream, LengthFormat, Memory<byte>, NumberStyles, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<T>(Stream, LengthFormat, Memory<byte>, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<TArg, TResult>(Stream, TArg, ReadOnlySpanFunc<char, TArg, TResult>, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.ReadAllAsync(Stream, int, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadBigEndianAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadBlockAsync(Stream, LengthFormat, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadExactlyAsync(Stream, long, int, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadLittleEndianAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadUtf8(Stream, Span<byte>, IBufferWriter<char>)
StreamExtensions.ReadUtf8Async(Stream, Memory<byte>, IBufferWriter<char>, CancellationToken)
StreamExtensions.ReadUtf8Async<TArg>(Stream, Memory<byte>, Memory<char>, Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask>, TArg, CancellationToken)
StreamExtensions.ReadUtf8<TArg>(Stream, Span<byte>, Span<char>, ReadOnlySpanAction<char, TArg>, TArg)
StreamExtensions.WriteAsync(Stream, ReadOnlySequence<byte>, CancellationToken)
StreamExtensions.WriteAsync(Stream, ReadOnlyMemory<byte>, LengthFormat, Memory<byte>, CancellationToken)
StreamExtensions.WriteAsync<T>(Stream, T, Memory<byte>, CancellationToken)
StreamExtensions.WriteBigEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)
StreamExtensions.WriteLittleEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾