func (f *File) WriteToIndent(w io.Writer, indent string) (n int64, err error) {
	equalSign := "="
	if PrettyFormat {
		equalSign = " = "
	}
	buf := bytes.NewBuffer(nil)
	for i, sname := range f.sectionList {
		sec := f.Section(sname)
		if len(sec.Comment) > 0 {
			if sec.Comment[0] != '#' && sec.Comment[0] != ';' {
				sec.Comment = "; " + sec.Comment
			}
			if _, err = buf.WriteString(sec.Comment + LineBreak); err != nil {
				return 0, err
			}
		}
		if i > 0 || DefaultHeader {
			if _, err = buf.WriteString("[" + sname + "]" + LineBreak); err != nil {
				return 0, err
			}
		} else {
			if len(sec.keyList) == 0 {
				continue
			}
		}
		alignLength := 0
		if PrettyFormat {
			for i := 0; i < len(sec.keyList); i++ {
				if len(sec.keyList[i]) > alignLength {
					alignLength = len(sec.keyList[i])
				}
			}
		}
		alignSpaces := bytes.Repeat([]byte(" "), alignLength)
		for _, kname := range sec.keyList {
			key := sec.Key(kname)
			if len(key.Comment) > 0 {
				if len(indent) > 0 && sname != DEFAULT_SECTION {
					buf.WriteString(indent)
				}
				if key.Comment[0] != '#' && key.Comment[0] != ';' {
					key.Comment = "; " + key.Comment
				}
				if _, err = buf.WriteString(key.Comment + LineBreak); err != nil {
					return 0, err
				}
			}
			if len(indent) > 0 && sname != DEFAULT_SECTION {
				buf.WriteString(indent)
			}
			switch {
			case key.isAutoIncr:
				kname = "-"
			case strings.ContainsAny(kname, "\"=:"):
				kname = "`" + kname + "`"
			case strings.Contains(kname, "`"):
				kname = `"""` + kname + `"""`
			}
			if _, err = buf.WriteString(kname); err != nil {
				return 0, err
			}
			if PrettyFormat {
				buf.Write(alignSpaces[:alignLength-len(kname)])
			}
			val := key.value
			if strings.ContainsAny(val, "\n`") {
				val = `"""` + val + `"""`
			} else if strings.ContainsAny(val, "#;") {
				val = "`" + val + "`"
			}
			if _, err = buf.WriteString(equalSign + val + LineBreak); err != nil {
				return 0, err
			}
		}
		if _, err = buf.WriteString(LineBreak); err != nil {
			return 0, err
		}
	}
	return buf.WriteTo(w)
}
WriteToIndent writes content into io.Writer with given indention.
If PrettyFormat has been set to be true,
it will align "=" sign with spaces under each section.
package ini
import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"
	"regexp"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"time"
)
const (
	DEFAULT_SECTION = "DEFAULT"
	_DEPTH_VALUES = 99
	_VERSION      = "1.11.0"
)
func Version() string {
	return _VERSION
}
var (
	LineBreak = "\n"
	varPattern = regexp.MustCompile(`%\(([^\)]+)\)s`)
	PrettyFormat = true
	DefaultHeader = false
)
func init() {
	if runtime.GOOS == "windows" {
		LineBreak = "\r\n"
	}
}
func inSlice(str string, s []string) bool {
	for _, v := range s {
		if str == v {
			return true
		}
	}
	return false
}
type dataSource interface {
	ReadCloser() (io.ReadCloser, error)
}
type sourceFile struct {
	name string
}
func (s sourceFile) ReadCloser() (_ io.ReadCloser, err error) {
	return os.Open(s.name)
}
type bytesReadCloser struct {
	reader io.Reader
}
func (rc *bytesReadCloser) Read(p []byte) (n int, err error) {
	return rc.reader.Read(p)
}
func (rc *bytesReadCloser) Close() error {
	return nil
}
type sourceData struct {
	data []byte
}
func (s *sourceData) ReadCloser() (io.ReadCloser, error) {
	return &bytesReadCloser{bytes.NewReader(s.data)}, nil
}
type File struct {
	BlockMode bool
	lock sync.RWMutex
	dataSources []dataSource
	sections map[string]*Section
	sectionList []string
	looseMode bool
	NameMapper
}
func newFile(dataSources []dataSource, looseMode bool) *File {
	return &File{
		BlockMode:   true,
		dataSources: dataSources,
		sections:    make(map[string]*Section),
		sectionList: make([]string, 0, 10),
		looseMode:   looseMode,
	}
}
func parseDataSource(source interface{}) (dataSource, error) {
	switch s := source.(type) {
	case string:
		return sourceFile{s}, nil
	case []byte:
		return &sourceData{s}, nil
	default:
		return nil, fmt.Errorf("error parsing data source: unknown type '%s'", s)
	}
}
func loadSources(looseMode bool, source interface{}, others ...interface{}) (_ *File, err error) {
	sources := make([]dataSource, len(others)+1)
	sources[0], err = parseDataSource(source)
	if err != nil {
		return nil, err
	}
	for i := range others {
		sources[i+1], err = parseDataSource(others[i])
		if err != nil {
			return nil, err
		}
	}
	f := newFile(sources, looseMode)
	if err = f.Reload(); err != nil {
		return nil, err
	}
	return f, nil
}
func Load(source interface{}, others ...interface{}) (*File, error) {
	return loadSources(false, source, others...)
}
func LooseLoad(source interface{}, others ...interface{}) (*File, error) {
	return loadSources(true, source, others...)
}
func Empty() *File {
	f, _ := Load([]byte(""))
	return f
}
func (f *File) NewSection(name string) (*Section, error) {
	if len(name) == 0 {
		return nil, errors.New("error creating new section: empty section name")
	}
	if f.BlockMode {
		f.lock.Lock()
		defer f.lock.Unlock()
	}
	if inSlice(name, f.sectionList) {
		return f.sections[name], nil
	}
	f.sectionList = append(f.sectionList, name)
	f.sections[name] = newSection(f, name)
	return f.sections[name], nil
}
func (f *File) NewSections(names ...string) (err error) {
	for _, name := range names {
		if _, err = f.NewSection(name); err != nil {
			return err
		}
	}
	return nil
}
func (f *File) GetSection(name string) (*Section, error) {
	if len(name) == 0 {
		name = DEFAULT_SECTION
	}
	if f.BlockMode {
		f.lock.RLock()
		defer f.lock.RUnlock()
	}
	sec := f.sections[name]
	if sec == nil {
		return nil, fmt.Errorf("section '%s' does not exist", name)
	}
	return sec, nil
}
func (f *File) Section(name string) *Section {
	sec, err := f.GetSection(name)
	if err != nil {
		sec, _ = f.NewSection(name)
		return sec
	}
	return sec
}
func (f *File) Sections() []*Section {
	sections := make([]*Section, len(f.sectionList))
	for i := range f.sectionList {
		sections[i] = f.Section(f.sectionList[i])
	}
	return sections
}
func (f *File) SectionStrings() []string {
	list := make([]string, len(f.sectionList))
	copy(list, f.sectionList)
	return list
}
func (f *File) DeleteSection(name string) {
	if f.BlockMode {
		f.lock.Lock()
		defer f.lock.Unlock()
	}
	if len(name) == 0 {
		name = DEFAULT_SECTION
	}
	for i, s := range f.sectionList {
		if s == name {
			f.sectionList = append(f.sectionList[:i], f.sectionList[i+1:]...)
			delete(f.sections, name)
			return
		}
	}
}
func (f *File) reload(s dataSource) error {
	r, err := s.ReadCloser()
	if err != nil {
		return err
	}
	defer r.Close()
	return f.parse(r)
}
func (f *File) Reload() (err error) {
	for _, s := range f.dataSources {
		if err = f.reload(s); err != nil {
			if os.IsNotExist(err) && f.looseMode {
				f.parse(bytes.NewBuffer(nil))
				continue
			}
			return err
		}
	}
	return nil
}
func (f *File) Append(source interface{}, others ...interface{}) error {
	ds, err := parseDataSource(source)
	if err != nil {
		return err
	}
	f.dataSources = append(f.dataSources, ds)
	for _, s := range others {
		ds, err = parseDataSource(s)
		if err != nil {
			return err
		}
		f.dataSources = append(f.dataSources, ds)
	}
	return f.Reload()
}