9type closerFunc func() error
11func (f closerFunc) Close() error {
15// Base64Writer turns a writer for data into one that writes base64 content on
16// \r\n separated lines of max 78+2 characters length.
17func Base64Writer(w io.Writer) io.WriteCloser {
18 lw := &lineWrapper{w: w}
19 bw := base64.NewEncoder(base64.StdEncoding, lw)
25 Closer: closerFunc(func() error {
26 if err := bw.Close(); err != nil {
34type lineWrapper struct {
36 n int // Written on current line.
39func (lw *lineWrapper) Write(buf []byte) (int, error) {
46 nn, err := lw.w.Write(buf[:n])
56 _, err := lw.w.Write([]byte("\r\n"))
66func (lw *lineWrapper) Close() error {
69 _, err := lw.w.Write([]byte("\r\n"))