Reset will re-initialize the writer and new writes will encode to the supplied writer as a new, independent stream.
(w io.Writer)
| 101 | // Reset will re-initialize the writer and new writes will encode to the supplied writer |
| 102 | // as a new, independent stream. |
| 103 | func (e *Encoder) Reset(w io.Writer) { |
| 104 | s := &e.state |
| 105 | |
| 106 | if e.o.concurrentBlocks { |
| 107 | e.shutdownJobWorkers() |
| 108 | js := &s.jobs |
| 109 | js.jobSize = e.o.jobSize() |
| 110 | js.overlapSize = e.o.overlapSize() |
| 111 | // js.filling is allocated lazily on first Write/ReadFrom so callers |
| 112 | // that only use EncodeAll don't pay the (up to ~32 MB) jobSize cost. |
| 113 | js.filling = js.filling[:0] |
| 114 | if js.nextPrefix != nil { |
| 115 | js.putOverlapBuf(js.nextPrefix) |
| 116 | js.nextPrefix = nil |
| 117 | } |
| 118 | js.jobSeq = 0 |
| 119 | js.flushedSeq = 0 |
| 120 | js.flusherErr = nil |
| 121 | js.started = false |
| 122 | } |
| 123 | |
| 124 | s.wg.Wait() |
| 125 | s.wWg.Wait() |
| 126 | if cap(s.filling) == 0 { |
| 127 | s.filling = make([]byte, 0, e.o.blockSize) |
| 128 | } |
| 129 | if e.o.concurrent > 1 && !e.o.concurrentBlocks { |
| 130 | if cap(s.current) == 0 { |
| 131 | s.current = make([]byte, 0, e.o.blockSize) |
| 132 | } |
| 133 | if cap(s.previous) == 0 { |
| 134 | s.previous = make([]byte, 0, e.o.blockSize) |
| 135 | } |
| 136 | s.current = s.current[:0] |
| 137 | s.previous = s.previous[:0] |
| 138 | if s.writing == nil { |
| 139 | s.writing = &blockEnc{lowMem: e.o.lowMem} |
| 140 | s.writing.init() |
| 141 | } |
| 142 | s.writing.initNewEncode() |
| 143 | } |
| 144 | if s.encoder == nil { |
| 145 | s.encoder = e.o.encoder() |
| 146 | } |
| 147 | s.filling = s.filling[:0] |
| 148 | s.encoder.Reset(e.o.dict, false) |
| 149 | s.headerWritten = false |
| 150 | s.eofWritten = false |
| 151 | s.fullFrameWritten = false |
| 152 | s.w = w |
| 153 | s.err = nil |
| 154 | s.nWritten = 0 |
| 155 | s.nInput = 0 |
| 156 | s.writeErr = nil |
| 157 | s.frameContentSize = 0 |
| 158 | } |
| 159 | |
| 160 | // ResetWithOptions will re-initialize the writer and apply the given options |
no test coverage detected