Skip to content
EvilEngine.Mounts

IRandomAccess interface

public interface IRandomAccess : IDisposable

A read-only file read at any offset, without a position to seek. TryOpenAccess returns one, as does the OpenAccess extension, which throws FileNotFoundException where the Try form returns false. Archive readers keep one per archive and read it from many threads at once. The caller disposes it.

using var access = parent.OpenAccess(path);
var header = new byte[96];
access.ReadExactly(0, header);

The engine has HostFile for a file on disk, MemoryAccess for bytes in memory, SliceAccess for a range or several ranges of another access, and StreamAccess, which wraps a seekable stream behind a lock and is what TryOpenAccess’s default returns. AccessStream turns an access back into a Stream. The ReadExactly extension fills the whole buffer or throws EndOfStreamException when the file ends first.

Assembly
EvilEngine.Mounts
Commit
4ff877b1

Members

Length property

long Length { get; }

The file’s length in bytes.

Read method

int Read(long offset, Span<byte> buffer)

Reads up to buffer.Length bytes starting at offset into buffer and returns how many it read. It can return fewer, as it does when the file ends first, and returns 0 at or past the end. There’s no position to move, so an implementation has to take calls from several threads at once. Use ReadExactly when you need the whole buffer.