Reader
abstract class Reader < Iterator<Buffer>
Read data from a file.
Typical use is to use the Reader
factory function to instantiate an
object of an appropriate derived class based on the file extension of the
given path:
let reader <- Reader(path);
The whole contents of the file can be read at once with:
let buffer <- reader.slurp();
Alternatively, where the root element of the file is an array, the contents
may be read sequentially, one element at a time, using the
Iterator interface, from which Reader
derives.
Finally, close the file:
reader.close();
Factory Functions
Name | Description |
---|---|
Reader | Create a reader for a file. |
Member Functions
Name | Description |
---|---|
open | Open a file. |
slurp | Read the whole contents of the file into a buffer. |
close | Close the file. |
Factory Function Details
function Reader(path:String) -> Reader
Create a reader for a file.
- path: Path of the file.
Returns: the reader.
The file extension of path
is used to determine the precise type of the
returned object. Supported file extension are .json
, .yml
, and .yaml
.
Member Function Details
close
abstract function close()
Close the file.
open
abstract function open(path:String)
Open a file.
- path: Path of the file.
slurp
abstract function slurp() -> Buffer
Read the whole contents of the file into a buffer.
Returns: Buffer with the file contents.