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

Method WriteTo

flate/inflate.go:420–450  ·  view source on GitHub ↗

WriteTo implements the io.WriteTo interface for io.Copy and friends.

(w io.Writer)

Source from the content-addressed store, hash-verified

418
419// WriteTo implements the io.WriteTo interface for io.Copy and friends.
420func (f *decompressor) WriteTo(w io.Writer) (int64, error) {
421 total := int64(0)
422 flushed := false
423 for {
424 if len(f.toRead) > 0 {
425 n, err := w.Write(f.toRead)
426 total += int64(n)
427 if err != nil {
428 f.err = err
429 return total, err
430 }
431 if n != len(f.toRead) {
432 return total, io.ErrShortWrite
433 }
434 f.toRead = f.toRead[:0]
435 }
436 if f.err != nil && flushed {
437 if f.err == io.EOF {
438 return total, nil
439 }
440 return total, f.err
441 }
442 if f.err == nil {
443 f.doStep()
444 }
445 if len(f.toRead) == 0 && f.err != nil && !flushed {
446 f.toRead = f.dict.readFlush() // Flush what's left in case of error
447 flushed = true
448 }
449 }
450}
451
452func (f *decompressor) Close() error {
453 if f.err == io.EOF {

Callers 2

TestWriteToFunction · 0.45
testDeterministicFunction · 0.45

Calls 3

doStepMethod · 0.95
readFlushMethod · 0.80
WriteMethod · 0.65

Tested by 2

TestWriteToFunction · 0.36
testDeterministicFunction · 0.36