From 71eb68cc467c35a70c4b3d0c46b590260fe3f303 Mon Sep 17 00:00:00 2001 From: Andy Balholm Date: Thu, 4 Jul 2019 08:13:24 -0700 Subject: [PATCH] Preserve compression settings when Writer is reset. Fixes #6 --- encode.go | 3 ++- writer.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/encode.go b/encode.go index 0dd3a3e..c01322b 100644 --- a/encode.go +++ b/encode.go @@ -72,7 +72,8 @@ const ( ) type Writer struct { - dst io.Writer + dst io.Writer + options WriterOptions params encoderParams hasher_ hasherHandle diff --git a/writer.go b/writer.go index 92c128c..22f0faf 100644 --- a/writer.go +++ b/writer.go @@ -50,11 +50,8 @@ func NewWriterLevel(dst io.Writer, level int) *Writer { // NewWriterOptions is like NewWriter but specifies WriterOptions func NewWriterOptions(dst io.Writer, options WriterOptions) *Writer { w := new(Writer) + w.options = options w.Reset(dst) - w.params.quality = options.Quality - if options.LGWin > 0 { - w.params.lgwin = uint(options.LGWin) - } 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. 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 }