Dumper

Dumps YAML documents to files or streams.

User specified Representer and/or Resolver can be used to support new tags / data types.

Setters are provided to affect output details (style, encoding, etc.).

Constructors

this
this()
Undocumented in source.
this
this(string filename)

Construct a Dumper writing to a file.

this
this(YStream stream)

Construct a Dumper writing to a _stream. This is useful to e.g. write to memory.

Destructor

~this
~this()

Destroy the Dumper.

Members

Functions

dump
void dump(Node[] documents)

Dump one or more YAML _documents to the file/stream.

emit
void emit(Event[] events)
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(Dumper )
Undocumented in source.
opEquals
bool opEquals(Dumper )
Undocumented in source.

Properties

YAMLVersion
string YAMLVersion [@property setter]

Specify YAML version string. "1.1" by default.

canonical
bool canonical [@property setter]

Write scalars in canonical form?

encoding
Encoding encoding [@property setter]

Set character encoding to use. UTF-8 by default.

explicitEnd
bool explicitEnd [@property setter]

Always explicitly write document end?

explicitStart
bool explicitStart [@property setter]

Always explicitly write document start?

indent
uint indent [@property setter]

Set indentation width. 2 by default. Must not be zero.

lineBreak
LineBreak lineBreak [@property setter]

Set line break to use. Unix by default.

name
string name [@property setter]

Set stream name. Used in debugging messages.

representer
Representer representer [@property setter]

Specify custom Representer to use.

resolver
Resolver resolver [@property setter]

Specify custom Resolver to use.

tagDirectives
string[string] tagDirectives [@property setter]

Specify tag directives.

textWidth
uint textWidth [@property setter]

Set preferred text _width.

Examples

Write to a file:

auto node = Node([1, 2, 3, 4, 5]);
Dumper("file.yaml").dump(node);

Write multiple YAML documents to a file:

auto node1 = Node([1, 2, 3, 4, 5]);
auto node2 = Node("This document contains only one string");
Dumper("file.yaml").dump(node1, node2);

//Or with an array:
//Dumper("file.yaml").dump([node1, node2]);

Write to memory:

import std.stream;
auto stream = new YMemoryStream();
auto node = Node([1, 2, 3, 4, 5]);
Dumper(stream).dump(node);

Use a custom representer/resolver to support custom data types and/or implicit tags:

auto node = Node([1, 2, 3, 4, 5]);
auto representer = new Representer();
auto resolver = new Resolver();

//Add representer functions / resolver expressions here...

auto dumper = Dumper("file.yaml");
dumper.representer = representer;
dumper.resolver = resolver;
dumper.dump(node);

Meta