View Source PagedFile (PagedFile v1.0.5)

PagedFile provides fast reads and writes by using multiple buffers of page_size. This makes many :pread/:pwrite calls faster. Especially useful for read-modify-write use cases.

Example

{:ok, fp} = __MODULE__.open("test_file")
:ok = __MODULE__.pwrite(fp, 10, "hello")
{:ok, "hello"} = __MODULE__.pread(fp, 10, 5)
:ok = __MODULE__.close(fp)

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Writes all pending changes to disk and closes the file.

Deletes the given file. Same as :file.delete(filename)

Opens file File. Files are always opened for :read and :write and in :binary mode. The underlying usage of pages and memory can be controlled with the following options:any()

Performs a sequence of pread/3 in one operation, which is more efficient than calling them one at a time. Returns {ok, [Data, ...]}, where each Data, the result of the corresponding pread, is a binary or :eof if the requested position is beyond end of file.

Executes are of num bytes at the position loc.

Performs a sequence of pwrite/3 in one operation, which is more efficient than calling them one at a time. Returns :ok.

Writes data to the position loc in the file. This is call is executed asynchrounosly and the file size is extended if needed to complete this call.

Returns the current file size

Ensures that any all pages that have changes are written to disk.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec close(atom() | pid()) :: :ok

Writes all pending changes to disk and closes the file.

@spec delete(atom() | binary() | [atom() | list() | char()]) :: :ok | {:error, atom()}

Deletes the given file. Same as :file.delete(filename)

Link to this function

open(filename, args \\ [])

View Source
@spec open(binary() | list(), keyword()) :: {:ok, pid()}

Opens file File. Files are always opened for :read and :write and in :binary mode. The underlying usage of pages and memory can be controlled with the following options:any()

  • page_size - The default page size of loading disk data into memory and writing it back again.
  • max_pages - The maximum number of pages that should be kept in memory.
@spec pread(atom() | pid(), [{integer(), integer()}]) :: {:ok, [binary() | :eof]}

Performs a sequence of pread/3 in one operation, which is more efficient than calling them one at a time. Returns {ok, [Data, ...]}, where each Data, the result of the corresponding pread, is a binary or :eof if the requested position is beyond end of file.

@spec pread(atom() | pid(), integer(), integer()) :: {:ok, binary()} | :eof

Executes are of num bytes at the position loc.

@spec pwrite(atom() | pid(), [{integer(), binary()}]) :: :ok

Performs a sequence of pwrite/3 in one operation, which is more efficient than calling them one at a time. Returns :ok.

@spec pwrite(atom() | pid(), integer(), binary()) :: :ok

Writes data to the position loc in the file. This is call is executed asynchrounosly and the file size is extended if needed to complete this call.

@spec size(atom() | pid()) :: non_neg_integer()

Returns the current file size

@spec sync(atom() | pid()) :: :ok

Ensures that any all pages that have changes are written to disk.