Skip to content

Latest commit

 

History

History
161 lines (105 loc) · 6.9 KB

lfiles.md

File metadata and controls

161 lines (105 loc) · 6.9 KB

Module lfiles

A lazily evaluated file module.

Description

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.

Function Index

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.

Function Details

get_chars/3


get_chars(IODevice, Prompt, Number) -> Iterator

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/2


get_line(IODevice, Prompt) -> Iterator

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/2


put_chars(IODevice, Iterator) -> ok

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/2


read(IODevice, Number) -> Iterator

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/1


read_line(IODevice) -> Iterator

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/2


write(IODevice, Iterator) -> ok | {error, Reason}

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.