WriteTo writes data to w until there's no more data to write or when an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.
(w io.Writer)
| 285 | // The return value n is the number of bytes written. |
| 286 | // Any error encountered during the write is also returned. |
| 287 | func (d *Decoder) WriteTo(w io.Writer) (int64, error) { |
| 288 | var n int64 |
| 289 | for { |
| 290 | if len(d.current.b) > 0 { |
| 291 | n2, err2 := w.Write(d.current.b) |
| 292 | n += int64(n2) |
| 293 | if err2 != nil && (d.current.err == nil || d.current.err == io.EOF) { |
| 294 | d.current.err = err2 |
| 295 | } else if n2 != len(d.current.b) { |
| 296 | d.current.err = io.ErrShortWrite |
| 297 | } |
| 298 | } |
| 299 | if d.current.err != nil { |
| 300 | break |
| 301 | } |
| 302 | d.nextBlock(true) |
| 303 | } |
| 304 | err := d.current.err |
| 305 | if err != nil { |
| 306 | d.drainOutput() |
| 307 | } |
| 308 | if err == io.EOF { |
| 309 | err = nil |
| 310 | } |
| 311 | return n, err |
| 312 | } |
| 313 | |
| 314 | // DecodeAll allows stateless decoding of a blob of bytes. |
| 315 | // Output will be appended to dst, so if the destination size is known |