File.Behaviour behaviour (Raxol v0.5.0)

View Source

Defines the behaviour for file system operations. This is used for mocking in tests.

Summary

Callbacks

Checks if a file exists.

Creates a directory and its parent directories.

Reads file contents.

Removes a file.

Gets file statistics.

Writes content to a file.

Callbacks

exists?(path)

@callback exists?(path :: String.t()) :: boolean()

Checks if a file exists.

mkdir_p(path)

@callback mkdir_p(path :: String.t()) :: :ok | {:error, File.posix()}

Creates a directory and its parent directories.

read(path)

@callback read(path :: String.t()) :: {:ok, binary()} | {:error, File.posix()}

Reads file contents.

rm(path)

@callback rm(path :: String.t()) :: :ok | {:error, File.posix()}

Removes a file.

stat(path)

@callback stat(path :: String.t()) :: {:ok, File.Stat.t()} | {:error, File.posix()}

Gets file statistics.

write(path, content)

@callback write(path :: String.t(), content :: binary()) :: :ok | {:error, File.posix()}

Writes content to a file.