IOData.File (iodata v0.6.0)

A structure that represents a file and can be used with IOData. A File can be opened or wrapped around an existing file-descriptor or reference.

Examples

iex> {:ok, slice} = IOData.File.open("path/to/file")
iex> IOData.to_binary(slice)
{:ok, <<0, 1, 2, 3, 4, 5, 6, 7, 8, 9>>}

iex> {head, tail} = IOData.split!(slice, 5)
iex> IOData.to_binary(tail)
{:ok, <<5, 6, 7, 8, 9>>}

Summary

Functions

Opens a file and returns a slice that can be used with IOData. The slice represents the entire file.

Opens a file and returns a slice that can be used with IOData. The slice represents the entire file. If the file cannot be opened, an exception is raised.

Wraps an existing file or reference in a slice that can be used with IOData. A length is required in order to provide boundary checking.

Types

t()

@type t() :: %IOData.File{
  count: non_neg_integer(),
  file: pid() | reference(),
  start: non_neg_integer()
}

Functions

open(path)

@spec open(path :: String.t()) :: {:ok, t()} | {:error, term()}

Opens a file and returns a slice that can be used with IOData. The slice represents the entire file.

open!(path)

@spec open!(path :: String.t()) :: t()

Opens a file and returns a slice that can be used with IOData. The slice represents the entire file. If the file cannot be opened, an exception is raised.

wrap(file, start \\ 0, count)

@spec wrap(
  file :: pid() | reference(),
  start :: non_neg_integer(),
  count :: non_neg_integer()
) :: t()

Wraps an existing file or reference in a slice that can be used with IOData. A length is required in order to provide boundary checking.