func (w *Writer) writeHeader() error {
	data, err := w.h.marshalBinary()
	if err != nil {
		return err
	}
	_, err = w.bw.(io.Writer).Write(data)
	return err
}
writeHeader writes the LZMA header into the stream.
package lzma
import (
	"bufio"
	"errors"
	"io"
)
const (
	MinDictCap = 1 << 12
	MaxDictCap = 1<<32 - 1
)
type WriterConfig struct {
	Properties *Properties
	DictCap int
	BufSize int
	Matcher MatchAlgorithm
	SizeInHeader bool
	Size int64
	EOSMarker bool
}
func (c *WriterConfig) fill() {
	if c.Properties == nil {
		c.Properties = &Properties{LC: 3, LP: 0, PB: 2}
	}
	if c.DictCap == 0 {
		c.DictCap = 8 * 1024 * 1024
	}
	if c.BufSize == 0 {
		c.BufSize = 4096
	}
	if c.Size > 0 {
		c.SizeInHeader = true
	}
	if !c.SizeInHeader {
		c.EOSMarker = true
	}
}
func (c *WriterConfig) Verify() error {
	c.fill()
	var err error
	if c == nil {
		return errors.New("lzma: WriterConfig is nil")
	}
	if c.Properties == nil {
		return errors.New("lzma: WriterConfig has no Properties set")
	}
	if err = c.Properties.verify(); err != nil {
		return err
	}
	if !(MinDictCap <= c.DictCap && int64(c.DictCap) <= MaxDictCap) {
		return errors.New("lzma: dictionary capacity is out of range")
	}
	if !(maxMatchLen <= c.BufSize) {
		return errors.New("lzma: lookahead buffer size too small")
	}
	if c.SizeInHeader {
		if c.Size < 0 {
			return errors.New("lzma: negative size not supported")
		}
	} else if !c.EOSMarker {
		return errors.New("lzma: EOS marker is required")
	}
	if err = c.Matcher.verify(); err != nil {
		return err
	}
	return nil
}
func (c *WriterConfig) header() header {
	h := header{
		properties: *c.Properties,
		dictCap:    c.DictCap,
		size:       -1,
	}
	if c.SizeInHeader {
		h.size = c.Size
	}
	return h
}
type Writer struct {
	h   header
	bw  io.ByteWriter
	buf *bufio.Writer
	e   *encoder
}
func (c WriterConfig) NewWriter(lzma io.Writer) (w *Writer, err error) {
	if err = c.Verify(); err != nil {
		return nil, err
	}
	w = &Writer{h: c.header()}
	var ok bool
	w.bw, ok = lzma.(io.ByteWriter)
	if !ok {
		w.buf = bufio.NewWriter(lzma)
		w.bw = w.buf
	}
	state := newState(w.h.properties)
	m, err := c.Matcher.new(w.h.dictCap)
	if err != nil {
		return nil, err
	}
	dict, err := newEncoderDict(w.h.dictCap, c.BufSize, m)
	if err != nil {
		return nil, err
	}
	var flags encoderFlags
	if c.EOSMarker {
		flags = eosMarker
	}
	if w.e, err = newEncoder(w.bw, state, dict, flags); err != nil {
		return nil, err
	}
	if err = w.writeHeader(); err != nil {
		return nil, err
	}
	return w, nil
}
func NewWriter(lzma io.Writer) (w *Writer, err error) {
	return WriterConfig{}.NewWriter(lzma)
}