# `Minga.Buffer.Persistence`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/buffer/persistence.ex#L1)

Stateless file persistence operations for buffers.

`Minga.Buffer.Process` owns the process transaction: undo state, dirty state, events, timers, and registry updates. This module owns the file-system and remote-storage details that make those transactions possible: reading content, writing content, collecting file metadata, fingerprinting saved content, and deciding whether the backing file changed since the buffer last saved or loaded it.

# `metadata`

```elixir
@type metadata() :: {mtime :: integer() | nil, size :: non_neg_integer() | nil}
```

# `saved_content_status`

```elixir
@type saved_content_status() :: Minga.Buffer.SaveState.saved_content_status()
```

# `state_or_storage`

```elixir
@type state_or_storage() :: Minga.Buffer.State.t() | storage()
```

# `storage`

```elixir
@type storage() :: Minga.Buffer.State.storage()
```

# `changed_since_saved?`

```elixir
@spec changed_since_saved?(
  Minga.Buffer.State.t(),
  integer() | nil,
  non_neg_integer() | nil
) ::
  boolean()
```

Returns true when the backing file differs from the buffer's saved baseline.

# `content_fingerprint`

```elixir
@spec content_fingerprint(String.t()) :: binary()
```

Fingerprints content with the algorithm used to track saved file baselines.

# `file_info`

```elixir
@spec file_info(state_or_storage(), String.t()) ::
  {:ok, File.Stat.t()} | {:error, term()}
```

Returns file information through the buffer's storage backend.

# `file_metadata`

```elixir
@spec file_metadata(state_or_storage(), String.t() | nil) :: metadata()
```

Returns `{mtime, size}` for a file, or `{nil, nil}` when metadata cannot be read.

# `load_content`

```elixir
@spec load_content(storage(), String.t() | nil, String.t()) ::
  {:ok, String.t(), String.t() | nil, metadata()} | {:error, term()}
```

Loads initial buffer content from storage or returns the supplied scratch content when no path is set.

# `read_content`

```elixir
@spec read_content(state_or_storage(), String.t()) ::
  {:ok, String.t()} | {:error, term()}
```

Reads file content through the buffer's storage backend.

# `saved_content_fingerprint`

```elixir
@spec saved_content_fingerprint(String.t() | nil, integer() | nil, String.t()) ::
  binary() | nil
```

Returns a saved-content fingerprint only when a path and concrete mtime make the baseline meaningful.

# `write_content`

```elixir
@spec write_content(Minga.Buffer.State.t(), String.t(), String.t()) ::
  :ok | {:error, term()}
```

Writes file content through the buffer's storage backend.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
