Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​IO.​RandomAccess
Assembly: System.Runtime
Inheritance: object → RandomAccess
Provides offset-based APIs for reading and writing files in a thread-safe manner.
Methods
public static
void
FlushToDisk​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle)
Flushes the operating system buffers for the given file to disk.
handle
The file handle.
public static
long
GetLength​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle)
Gets the length of the file in bytes.
Returns A long value representing the length of the file in bytes.
handle
The file handle.
public static
long
Read​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Collections.​Generic.​IReadOnlyList<​Memory<​byte>> buffers,
long fileOffset)
Reads a sequence of bytes from given file at given offset.
Returns The total number of bytes read into the buffers. This can be less than the number of bytes allocated in the buffers if that many bytes are not currently available, or zero (0) if the end of the file has been reached.
handle
The file handle.
buffers
A list of memory buffers. When this method returns, the contents of the buffers are replaced by the bytes read from the file.
fileOffset
The file position to read from.
public static
int
Read​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Span<​byte> buffer,
long fileOffset)
Reads a sequence of bytes from given file at given offset.
Returns The total number of bytes read into the buffer. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or zero (0) if the end of the file has been reached.
handle
The file handle.
buffer
A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the file.
fileOffset
The file position to read from.
public static
Threading.​Tasks.​ValueTask<​long>
ReadAsync​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Collections.​Generic.​IReadOnlyList<​Memory<​byte>> buffers,
long fileOffset,
Threading.​CancellationToken cancellationToken = null)
Reads a sequence of bytes from given file at given offset.
Returns The total number of bytes read into the buffers. This can be less than the number of bytes allocated in the buffers if that many bytes are not currently available, or zero (0) if the end of the file has been reached.
handle
The file handle.
buffers
A list of memory buffers. When this method returns, the contents of these buffers are replaced by the bytes read from the file.
fileOffset
The file position to read from.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
Threading.​Tasks.​ValueTask<​int>
ReadAsync​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Memory<​byte> buffer,
long fileOffset,
Threading.​CancellationToken cancellationToken = null)
Reads a sequence of bytes from given file at given offset.
Returns The total number of bytes read into the buffer. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or zero (0) if the end of the file has been reached.
handle
The file handle.
buffer
A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the file.
fileOffset
The file position to read from.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
void
SetLength​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
long length)
Sets the length of the file to the given value.
handle
The file handle.
length
The length of the file in bytes.
public static
void
Write​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Collections.​Generic.​IReadOnlyList<​ReadOnlyMemory<​byte>> buffers,
long fileOffset)
Writes a sequence of bytes from given buffers to given file at given offset.
handle
The file handle.
buffers
A list of memory buffers. This method copies the contents of these buffers to the file.
fileOffset
The file position to write to.
public static
void
Write​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
ReadOnlySpan<​byte> buffer,
long fileOffset)
Writes a sequence of bytes from given buffer to given file at given offset.
handle
The file handle.
buffer
A region of memory. This method copies the contents of this region to the file.
fileOffset
The file position to write to.
WriteAsync​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
Collections.​Generic.​IReadOnlyList<​ReadOnlyMemory<​byte>> buffers,
long fileOffset,
Threading.​CancellationToken cancellationToken = null)
Writes a sequence of bytes from given buffers to given file at given offset.
Returns A task representing the asynchronous completion of the write operation.
handle
The file handle.
buffers
A list of memory buffers. This method copies the contents of these buffers to the file.
fileOffset
The file position to write to.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
WriteAsync​(Microsoft.​Win32.​SafeHandles.​SafeFileHandle handle,
ReadOnlyMemory<​byte> buffer,
long fileOffset,
Threading.​CancellationToken cancellationToken = null)
Writes a sequence of bytes from given buffer to given file at given offset.
Returns A task representing the asynchronous completion of the write operation.
handle
The file handle.
buffer
A region of memory. This method copies the contents of this region to the file.
fileOffset
The file position to write to.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.