Preserve compression settings when Writer is reset.

Fixes #6
This commit is contained in:
Andy Balholm 2019-07-04 08:13:24 -07:00
parent 5f990b63d2
commit 71eb68cc46
2 changed files with 7 additions and 5 deletions

View File

@ -72,7 +72,8 @@ const (
) )
type Writer struct { type Writer struct {
dst io.Writer dst io.Writer
options WriterOptions
params encoderParams params encoderParams
hasher_ hasherHandle hasher_ hasherHandle

View File

@ -50,11 +50,8 @@ func NewWriterLevel(dst io.Writer, level int) *Writer {
// NewWriterOptions is like NewWriter but specifies WriterOptions // NewWriterOptions is like NewWriter but specifies WriterOptions
func NewWriterOptions(dst io.Writer, options WriterOptions) *Writer { func NewWriterOptions(dst io.Writer, options WriterOptions) *Writer {
w := new(Writer) w := new(Writer)
w.options = options
w.Reset(dst) w.Reset(dst)
w.params.quality = options.Quality
if options.LGWin > 0 {
w.params.lgwin = uint(options.LGWin)
}
return w return w
} }
@ -63,6 +60,10 @@ func NewWriterOptions(dst io.Writer, options WriterOptions) *Writer {
// instead. This permits reusing a Writer rather than allocating a new one. // instead. This permits reusing a Writer rather than allocating a new one.
func (w *Writer) Reset(dst io.Writer) { func (w *Writer) Reset(dst io.Writer) {
encoderInitState(w) encoderInitState(w)
w.params.quality = w.options.Quality
if w.options.LGWin > 0 {
w.params.lgwin = uint(w.options.LGWin)
}
w.dst = dst w.dst = dst
} }