A lazily evaluated file module.
This module provides replicas of
functions from the kernel file
and stdlib io
modules designed
to work with iterators as defined by the llists
module.
All iterators created by this module work by side effect, making them impure. As such, they should only be evaluated once.
As there is no guarantee that an iterator will be completely evaluated, this module expects the lifecycle of the opened file process to be managed by the caller.
get_chars/3 |
Create an iterator that returns chunks of Number characters from
IODevice , prompting each read with Prompt . |
get_line/2 |
Create an iterator that returns lines of data from a file
referenced by IODevice , prompting each read with Prompt . |
put_chars/2 |
Fully evaluate Iterator and write the characters returned to the
file referenced by IODevice . |
read/2 |
Create an iterator that returns chunks of data from a file
referenced by IODevice of approximately Number
bytes/characters. |
read_line/1 |
Create an iterator that returns lines of data from a file
referenced by IODevice . |
write/2 |
Fully evaluate Iterator and write the bytes returned to the file
referenced by IODevice . |
get_chars(IODevice, Prompt, Number) -> Iterator
IODevice = file:io_device()
Prompt = io:prompt()
Number = non_neg_integer()
Iterator = llists:iterator(Data)
Data = string() | unicode:unicode_binary()
Create an iterator that returns chunks of Number
characters from
IODevice
, prompting each read with Prompt
.
If the get_chars call fails, an error of form
{io_read_error, Reason}
will be thrown by the iterator.
See also: io:get_chars/3.
get_line(IODevice, Prompt) -> Iterator
IODevice = file:io_device()
Prompt = io:prompt()
Iterator = llists:iterator(Data)
Data = string() | unicode:unicode_binary()
Create an iterator that returns lines of data from a file
referenced by IODevice
, prompting each read with Prompt
.
The trailing linefeed (\n
) character is returned as part of the
line.
If the get_line call fails, an error of form
{io_read_error, Reason}
will be thrown by the iterator.
See also: io:get_line/2.
put_chars(IODevice, Iterator) -> ok
IODevice = file:io_device()
Iterator = llists:iterator(unicode:chardata())
Fully evaluate Iterator
and write the characters returned to the
file referenced by IODevice
.
The iterator will be fully evaluated, infinite iterators will never return (or will fill up the disk and error!).
See also: io:put_chars/2.
read(IODevice, Number) -> Iterator
IODevice = file:io_device()
Number = non_neg_integer()
Iterator = llists:iterator(Data)
Data = string() | binary()
Create an iterator that returns chunks of data from a file
referenced by IODevice
of approximately Number
bytes/characters.
If the read fails, an error of form {file_read_error, Reason}
will be thrown by the iterator.
See also: file:read/2.
read_line(IODevice) -> Iterator
IODevice = file:io_device()
Iterator = llists:iterator(Data)
Data = string() | binary()
Create an iterator that returns lines of data from a file
referenced by IODevice
.
The trailing linefeed (\n
) character is returned as part of the
line.
If the read fails, an error of form {file_read_error, Reason}
will be thrown by the iterator.
See also: file:read_line/1.
write(IODevice, Iterator) -> ok | {error, Reason}
IODevice = file:io_device()
Iterator = llists:iterator(file:io_data())
Reason = file:posix() | badarg | terminated
Fully evaluate Iterator
and write the bytes returned to the file
referenced by IODevice
.
ok
is returned on success, but if the write fails an error of
form {error, Reason}
will be returned.
The iterator will be fully evaluated, infinite iterators will never return (or will fill up the disk and error!).
See also: file:write/2.