Writer

abstract class Writer < Object

Abstract 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:

auto writer <- Writer(path);


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

writer.write(buffer);


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

writer.startSequence();
writer.write(buffer1);
writer.write(buffer2);
writer.write(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.
write Write the entire contents of 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.

startMapping

abstract function startMapping()

Start a mapping.

startSequence

abstract function startSequence()

Start a sequence.

write

abstract function write(buffer:MemoryBuffer)

Write the entire contents of the file.

• buffer: Buffer to write.