Minga.Buffer.Persistence (Minga v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

Returns file information through the buffer's storage backend.

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

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

Reads file content through the buffer's storage backend.

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

Writes file content through the buffer's storage backend.

Types

metadata()

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

saved_content_status()

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

state_or_storage()

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

storage()

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

Functions

changed_since_saved?(state, disk_mtime, disk_size)

@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(content)

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

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

file_info(arg1, path)

@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(state_or_storage, path)

@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(storage, file_path, initial_content)

@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(arg1, path)

@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(path, mtime, content)

@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(state, file_path, content)

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

Writes file content through the buffer's storage backend.