ics - encoder.go
1 package ics
2
3 import (
4 "errors"
5 "io"
6 )
7
8 type writer interface {
9 io.Writer
10 WriteString(string) (int, error)
11 }
12
13 // Encode encodes the given iCalendar object into the writer. It first
14 // validates the iCalendar object so as not to write invalid data to the writer.
15 func Encode(w io.Writer, cal *Calendar) error {
16 if err := cal.valid(); err != nil {
17 return err
18 }
19
20 f := folder{w: w}
21
22 cal.encode(&f)
23
24 return f.err
25 }
26
27 // Errors.
28 var (
29 ErrInvalidCalendar = errors.New("invalid calendar")
30 )
31