View Source PagedFile (PagedFile v1.1.1)
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} = PagedFile.open("test_file")
:ok = PagedFile.pwrite(fp, 10, "hello")
{:ok, "hello"} = PagedFile.pread(fp, 10, 5)
:ok = PagedFile.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
.
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()
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.priority
- The process priority of the PagedReader.
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.
@spec size(atom() | pid()) :: non_neg_integer()
Returns the current file size
Ensures that any all pages that have changes are written to disk.