# IRandomAccess interface

> 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.

Namespace `EvilEngine.Mounts`, assembly `EvilEngine.Mounts`. Engine commit 4ff877b1.

```csharp
public interface IRandomAccess : IDisposable
```

A read-only file read at any offset, without a position to seek. [TryOpenAccess](/docs/api/ifilesource#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.

```csharp
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](/docs/api/ifilesource#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.

## Members

### Length (property)

```csharp
long Length { get; }
```

The file's length in bytes.

### Read (method)

```csharp
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.
