Skip to content

Parser and serializer for Mozilla Firefox and Thunderbird preference files written in Go

License

Notifications You must be signed in to change notification settings

hansmi/go-mozpref

Repository files navigation

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.

About

Parser and serializer for Mozilla Firefox and Thunderbird preference files written in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published