ResetWithOptions will re-initialize the writer and apply the given options as a new, independent stream. Options are applied on top of the existing options. Some options cannot be changed on reset and will return an error.
(w io.Writer, opts ...EOption)
| 162 | // Options are applied on top of the existing options. |
| 163 | // Some options cannot be changed on reset and will return an error. |
| 164 | func (e *Encoder) ResetWithOptions(w io.Writer, opts ...EOption) error { |
| 165 | e.o.resetOpt = true |
| 166 | defer func() { e.o.resetOpt = false }() |
| 167 | hadDict := e.o.dict != nil |
| 168 | for _, o := range opts { |
| 169 | if err := o(&e.o); err != nil { |
| 170 | return err |
| 171 | } |
| 172 | } |
| 173 | hasDict := e.o.dict != nil |
| 174 | if e.o.concurrentBlocks && hasDict { |
| 175 | e.o.concurrentBlocks = false |
| 176 | } |
| 177 | if hadDict != hasDict { |
| 178 | // Dict presence changed — encoder type must be recreated. |
| 179 | e.state.encoder = nil |
| 180 | e.init = sync.Once{} |
| 181 | } |
| 182 | e.Reset(w) |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | // ResetContentSize will reset and set a content size for the next stream. |
| 187 | // If the bytes written does not match the size given an error will be returned |