Skip to content

Writer


abstract class Writer

Writer.

Typical use is to use the Writer factory function to instantiate an object of an appropriate derived class based on the file extension of the given path:

let writer <- Writer(path);

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

writer.print(buffer);

A write of a sequence of buffers can be performed with:

writer.startSequence();
writer.print(buffer1);
writer.print(buffer2);
writer.print(buffer3);
writer.endSequence();

which is useful for not keeping the entire contents of the file, to be written, in memory.

Finally, close the file:

writer.close();

A file may not be valid until the writer is closed, depending on the file format.

Factory Functions

Name Description
Writer Create a writer for a file.

Member Functions

Name Description
open Open a file.
print Write the contents of a buffer into the file.
flush Flush accumulated writes to the file.
close Close the file.
startMapping Start a mapping.
endMapping End a mapping.
startSequence Start a sequence.
endSequence End a sequence.

Factory Function Details

function Writer(path:String) -> Writer

Create a writer for a file.

  • path: Path of the file.

Returns: the writer.

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.

endMapping

abstract function endMapping()

End a mapping.

endSequence

abstract function endSequence()

End a sequence.

flush

abstract function flush()

Flush accumulated writes to the file.

open

abstract function open(path:String)

Open a file.

  • path : Path of the file.

print

abstract function print(buffer:Buffer)

Write the contents of a buffer into the file.

  • buffer: Buffer to write.

startMapping

abstract function startMapping()

Start a mapping.

startSequence

abstract function startSequence()

Start a sequence.