func (w *Writer) Write(p []byte) (n int, err error) {
	return w.writeChunk(p, operationProcess)
}
Write implements io.Writer. Flush or Close must be called to ensure that the
encoded bytes are actually flushed to the underlying Writer.
package brotli
import (
	"errors"
	"io"
)
const (
	BestSpeed          = 0
	BestCompression    = 11
	DefaultCompression = 6
)
type WriterOptions struct {
	Quality int
	LGWin int
}
var (
	errEncode       = errors.New("brotli: encode error")
	errWriterClosed = errors.New("brotli: Writer is closed")
)
func NewWriter(dst io.Writer) *Writer {
	return NewWriterLevel(dst, DefaultCompression)
}
func NewWriterLevel(dst io.Writer, level int) *Writer {
	return NewWriterOptions(dst, WriterOptions{
		Quality: level,
	})
}
func NewWriterOptions(dst io.Writer, options WriterOptions) *Writer {
	w := new(Writer)
	w.options = options
	w.Reset(dst)
	return w
}
func (w *Writer) Reset(dst io.Writer) {
	encoderInitState(w)
	w.params.quality = w.options.Quality
	if w.options.LGWin > 0 {
		w.params.lgwin = uint(w.options.LGWin)
	}
	w.dst = dst
}
func (w *Writer) writeChunk(p []byte, op int) (n int, err error) {
	if w.dst == nil {
		return 0, errWriterClosed
	}
	for {
		availableIn := uint(len(p))
		nextIn := p
		success := encoderCompressStream(w, op, &availableIn, &nextIn)
		bytesConsumed := len(p) - int(availableIn)
		p = p[bytesConsumed:]
		n += bytesConsumed
		if !success {
			return n, errEncode
		}
		outputData := encoderTakeOutput(w)
		if len(outputData) > 0 {
			_, err = w.dst.Write(outputData)
			if err != nil {
				return n, err
			}
		}
		if len(p) == 0 {
			return n, nil
		}
	}
}
func (w *Writer) Flush() error {
	_, err := w.writeChunk(nil, operationFlush)
	return err
}
func (w *Writer) Close() error {
	_, err := w.writeChunk(nil, operationFinish)
	w.dst = nil
	return err
}