func WriteTo(l Library, w io.Writer) error {
	gzw, err := gzip.NewWriterLevel(w, gzip.BestSpeed)
	if err != nil {
		return err
	}
	defer gzw.Close()
	enc := json.NewEncoder(gzw)
	return enc.Encode(l)
}
WriteTo writes the Library data to the writer, currently using gzipped-JSON.
package index
import (
	"compress/gzip"
	"encoding/json"
	"fmt"
	"io"
	"time"
)
type Library interface {
	Tracks() []Track
	Track(identifier string) (Track, bool)
}
type Track interface {
	GetString(string) string
	GetStrings(string) []string
	GetInt(string) int
	GetTime(string) time.Time
}
func Convert(l Library, id string) *library {
	allTracks := l.Tracks()
	tracks := make(map[string]*track, len(allTracks))
	for _, t := range allTracks {
		identifier := t.GetString(id)
		tracks[identifier] = &track{
			ID:          identifier,
			Name:        t.GetString("Name"),
			Album:       t.GetString("Album"),
			AlbumArtist: t.GetString("AlbumArtist"),
			Artist:      t.GetString("Artist"),
			Composer:    t.GetString("Composer"),
			Genre:       t.GetString("Genre"),
			Location:    t.GetString("Location"),
			Kind:        t.GetString("Kind"),
			TotalTime:   t.GetInt("TotalTime"),
			Year:        t.GetInt("Year"),
			DiscNumber:  t.GetInt("DiscNumber"),
			TrackNumber: t.GetInt("TrackNumber"),
			TrackCount:  t.GetInt("TrackCount"),
			DiscCount:   t.GetInt("DiscCount"),
			BitRate:     t.GetInt("BitRate"),
			DateAdded:    t.GetTime("DateAdded"),
			DateModified: t.GetTime("DateModified"),
		}
	}
	return &library{
		tracks,
	}
}
type library struct {
	trks map[string]*track
}
func (l *library) Tracks() []Track {
	tracks := make([]Track, 0, len(l.trks))
	for _, t := range l.trks {
		tracks = append(tracks, t)
	}
	return tracks
}
func (l *library) Track(id string) (Track, bool) {
	t, ok := l.trks[id]
	return t, ok
}
func (l *library) MarshalJSON() ([]byte, error) {
	return json.Marshal(l.trks)
}
func (l *library) UnmarshalJSON(b []byte) error {
	l.trks = make(map[string]*track)
	return json.Unmarshal(b, &l.trks)
}