View Source ExWal.File protocol (ex_wal v0.3.0)

File protocol

Summary

Types

t()

All the types that implement this protocol.

Functions

fd returns the raw file descriptor when a File is backed by an :file. It can be used for specific functionality like Prefetch. Returns error if not supported.

prealloc optionally preallocates storage for length at offset within the file. Implementations may choose to do nothing.

prefetch signals the OS (on supported platforms) to fetch the next length bytes in file after offset into cache. Any subsequent reads in that range will not issue disk IO.

read reads n bytes from the file

read_at reads n bytes from the file at the given offset of datasource

sync_to requests that a prefix of the file's data be synced to stable storage. The caller passes provides a length, indicating how many bytes to sync from the beginning of the file. sync_to is a no-op for directories, and therefore always returns false.

write writes bytes to the file

write_at writes bytes to the file to the underlying data stream

Types

@type t() :: term()

All the types that implement this protocol.

Functions

@spec close(t()) :: :ok | {:error, reason :: term()}
@spec fd(impl :: t()) :: File.io_device() | {:error, reason :: term()}

fd returns the raw file descriptor when a File is backed by an :file. It can be used for specific functionality like Prefetch. Returns error if not supported.

Link to this function

prealloc(impl, offset, length)

View Source
@spec prealloc(impl :: t(), offset :: non_neg_integer(), length :: non_neg_integer()) ::
  :ok | {:error, reason :: term()}

prealloc optionally preallocates storage for length at offset within the file. Implementations may choose to do nothing.

Link to this function

prefetch(impl, offset, length)

View Source
@spec prefetch(impl :: t(), offset :: non_neg_integer(), length :: non_neg_integer()) ::
  :ok | {:error, reason :: term()}

prefetch signals the OS (on supported platforms) to fetch the next length bytes in file after offset into cache. Any subsequent reads in that range will not issue disk IO.

@spec read(impl :: t(), n_bytes :: non_neg_integer()) ::
  {:ok, bytes :: binary()} | :eof | {:error, reason :: term()}

read reads n bytes from the file

Link to this function

read_at(impl, n_bytes, offset)

View Source
@spec read_at(impl :: t(), n_bytes :: non_neg_integer(), offset :: non_neg_integer()) ::
  {:ok, bytes :: binary()} | :eof | {:error, reason :: term()}

read_at reads n bytes from the file at the given offset of datasource

@spec stat(impl :: t()) :: {:ok, stat :: File.Stat.t()} | {:error, reason :: term()}
@spec sync(impl :: t()) :: :ok | {:error, reason :: term()}
@spec sync_to(impl :: t(), length :: non_neg_integer()) ::
  {:ok, full_sync? :: boolean()} | {:error, reason :: term()}

sync_to requests that a prefix of the file's data be synced to stable storage. The caller passes provides a length, indicating how many bytes to sync from the beginning of the file. sync_to is a no-op for directories, and therefore always returns false.

@spec write(impl :: t(), bytes :: binary()) :: :ok | {:error, reason :: term()}

write writes bytes to the file

Link to this function

write_at(impl, bytes, offset)

View Source
@spec write_at(impl :: t(), bytes :: binary(), offset :: non_neg_integer()) ::
  :ok | {:error, reason :: term()}

write_at writes bytes to the file to the underlying data stream