func (w *Sink) Close() error {
	w.mu.Lock()
	defer w.mu.Unlock()
	if w.closed {
		return &CloseError{Close: ErrClosed}
	}
	w.closed = true
	e := &CloseError{}
	if len(w.buf) != 0 {
		e.Write = w.writeOut(w.buf)
	}
	w.buf = nil
	e.Close = w.out.Close()
	if e.Write == nil && e.Close == nil {
		return nil
	}
	return e
}
Close closes the Sink for further writes and writes any buffered data to the underlying writer.
Close returns a *CloseError if there were any errors. The Close fields will contain ErrClosed if the error was a result of closing a closed sink
package sink
import (
	"errors"
	"fmt"
	"io"
	"sync"
)
var ErrClosed = errors.New("Invalid use of closed sink")
type CloseError struct {
	Write error  
	Close error  
}
type Sink struct {
	closed bool
	buf    []byte
	mu     sync.Mutex
	out    io.WriteCloser
}
func (w *Sink) Write(p []byte) (int, error) {
	w.mu.Lock()
	defer w.mu.Unlock()
	if w.closed {
		return 0, ErrClosed
	}
	var err error
	n := len(p)
	if len(w.buf) != 0 {
		p = append(w.buf, p...)
	}
	for len(p) > 0 && err == nil {
		i := nextChunk(p)
		if i < 0 {
			break
		}
		err = w.writeOut(p[:i])
		p = p[i:]
	}
	w.buf = append(w.buf[:0], p...)
	return n, err
}
func (w *Sink) writeOut(p []byte) error {
	_, err := w.out.Write(cp(p))
	return err
}