Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 1.46 KB

README.md

File metadata and controls

76 lines (54 loc) · 1.46 KB

go-mozpref

GoDoc

go-mozpref is a Go library for reading and writing preference files as used by Mozilla Firefox and Thunderbird. The parser consists of a Ragel-generated state machine.

Usage

import mozpref "github.com/hansmi/go-mozpref"

Preferences can be read from any io.Reader:

file, err := os.Open("prefs.js")
if err != nil {
	// Handle error
}

prefs, err := mozpref.ReadFrom(file)
if err != nil {
	// Handle error
}

for name, p := range prefs {
	fmt.Printf("%s = %s\n", name, p.Value)
}

Writing works likewise with any io.Writer:

prefs := mozpref.PrefMap{
	"example": mozpref.Pref{
		Value: true,
		Flags: mozpref.Locked,
	},
}

_, err := prefs.WriteTo(os.Stdout)
if err != nil {
	// Handle error
}

Preferences can be marked as locked or sticky:

prefs["example"].Flags |= mozpref.Sticky
prefs["other"] = &mozpref.Pref{
	Value: "Hello World",
	Flags: mozpref.Locked | mozpref.Sticky,
}

Entries suitable for user.js files can be written using the mozpref.UserPref flag.

Versioning

go-mozpref follows semver.

License

This library is distributed under the BSD-style license found in the LICENSE file.