WriteTo 写入内容, 并更新字典 Write the contents, and update the dictionary
(w io.Writer)
| 205 | // WriteTo 写入内容, 并更新字典 |
| 206 | // Write the contents, and update the dictionary |
| 207 | func (c *readerWrapper) WriteTo(w io.Writer) (int64, error) { |
| 208 | var buf = binaryPool.Get(segmentSize) |
| 209 | defer binaryPool.Put(buf) |
| 210 | |
| 211 | var p = buf.Bytes()[:segmentSize] |
| 212 | var sum, n = 0, 0 |
| 213 | var err error |
| 214 | for n, err = c.r.Read(p); err == nil || errors.Is(err, io.EOF); n, err = c.r.Read(p) { |
| 215 | eof := errors.Is(err, io.EOF) |
| 216 | if _, err = w.Write(p[:n]); err != nil { |
| 217 | return int64(sum), err |
| 218 | } |
| 219 | sum += n |
| 220 | _, _ = c.sw.Write(p[:n]) |
| 221 | if eof { |
| 222 | break |
| 223 | } |
| 224 | } |
| 225 | return int64(sum), err |
| 226 | } |