Skip to content

Reader

abstract class Reader < Object

Abstract reader.

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:

auto reader <- Reader(path);

A read of a single buffer can then be performed with:

reader.read(buffer);

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.
read Read the entire contents of the file.
close Close the file.

Member Fibers

Name Description
walk Read the contents of the file sequentially.

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 and .yml.

Member Function Details

close

abstract function close()

Close the file.

open

abstract function open(path:String)

Open a file.

  • path: Path of the file.

read

abstract function read(buffer:MemoryBuffer)

Read the entire contents of the file.

  • buffer: Buffer into which to read.

Member Fiber Details

walk

abstract fiber walk() -> Buffer

Read the contents of the file sequentially.

Yields: A buffer for each element of the top level sequence.

For a file that consists of a sequence at the top level, yields each element of that sequence one at a time, to avoid reading the whole file into memory at once.