MCPcopy
hub / github.com/klauspost/compress / WriteTo

Method WriteTo

zstd/decoder.go:287–312  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

285// The return value n is the number of bytes written.
286// Any error encountered during the write is also returned.
287func (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

Callers 2

WriteToMethod · 0.45
TestMainFunction · 0.45

Calls 3

nextBlockMethod · 0.95
drainOutputMethod · 0.95
WriteMethod · 0.65

Tested by 1

TestMainFunction · 0.36