ini 1.1.0

Dart INI

This library deals with reading and writing ini files. This implements the standard as defined here:

https://en.wikipedia.org/wiki/INI_file

The ini file reader will return data organized by section and option. The default section will be the blank string.

Examples

Read a file:

import "package:ini/ini.dart";

new File("config.ini").readAsLines()
    .then((lines) => new Config.fromStrings(lines))
    .then((Config config) => ...);

Write a file:

new File("config.ini").writeAsString(config.toString());

Read options:

// List all sections in the configuration, excluding default.
config.sections();

// List options within a section
config.options("default");
config.options("section");
config.hasSection("section");

// List of key value pairs for a section.
config.items("section");

// Read specific options.
config.get("section", "option");
config.hasOption("section", "option");

Write options:

// Make sure you add sections before using them.
config.addSection("section");

config.set("section", "option", "value");

config.removeSection("section");

config.removeOption("section", "option");

There is example code in the example/ directory.

example/example.dart

import 'package:ini/ini.dart';
import 'dart:io';

File file = new File("example/config.ini");

void doConfigThings(Config config, String label) {
  print("${label}: loaded config from ${file.path}");
  print('');

  print("${label}: Read some values...");
  print("${label}: ${config.hasOption('default', 'default')}");
  print("${label}: ${config.defaults()["default"]}");
  print("${label}: ${config.get("section", "section")}");
  print('');

  print("${label}: Write some values...");
  config.addSection("new");
  config.set("new", "entry", "result");
  print("${label}: Added a new section and entry");
  print('');

  print("${label}: Write out config (to screen)");
  print("${label}: ${config.toString()}");
}

void main() {
  file.readAsLines()
    .then((lines) => new Config.fromStrings(lines))
    .then((Config config) {
      doConfigThings(config, "async");
    });

  Config config = new Config.fromStrings(file.readAsLinesSync());
  doConfigThings(config, "sync");
}

// vim: set ai et sw=2 syntax=dart :

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  ini: "^1.1.0"

2. Install it

You can install packages from the command line:

$ pub get

Alternatively, your editor might support 'pub get'. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:ini/ini.dart';

Platforms

About

Read and write .ini files

Author

Email matthew.franglen@gmail.com Matthew Franglen

Homepage

github.com/matthewfranglen/dart-ini

Documentation

www.dartdocs.org/documentation/ini/1.1.0/

Source code (hyperlinked)

www.crossdart.info/p/ini/1.1.0/

Uploader

matthew.franglen@googlemail.com

License

GPL 3.0

Published

Mar 24, 2015

Share