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.).

Disabled Default Constructor

A disabled default is present on this object. To use it, use one of the other constructors or a factory function.

Constructors

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.

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:

1 auto node1 = Node([1, 2, 3, 4, 5]);
2 auto node2 = Node("This document contains only one string");
3 Dumper("file.yaml").dump(node1, node2);
4 
5 //Or with an array:
6 //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:

1 auto node = Node([1, 2, 3, 4, 5]);
2 auto representer = new Representer();
3 auto resolver = new Resolver();
4 
5 //Add representer functions / resolver expressions here...
6 
7 auto dumper = Dumper("file.yaml");
8 dumper.representer = representer;
9 dumper.resolver = resolver;
10 dumper.dump(node);

Meta