MCPcopy Create free account
hub / github.com/entireio/git-sync / Write

Method Write

internal/gitproto/push.go:669–694  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

667}
668
669func (p *prefixedLineWriter) Write(b []byte) (int, error) {
670 consumed := 0
671 for len(b) > 0 {
672 if p.atLineStart {
673 if _, err := io.WriteString(p.w, p.prefix); err != nil {
674 return consumed, fmt.Errorf("write prefix: %w", err)
675 }
676 p.atLineStart = false
677 }
678 i := bytes.IndexAny(b, "\r\n")
679 var chunk []byte
680 if i < 0 {
681 chunk = b
682 } else {
683 chunk = b[:i+1]
684 p.atLineStart = true
685 }
686 n, err := p.w.Write(chunk)
687 consumed += n
688 if err != nil {
689 return consumed, fmt.Errorf("write chunk: %w", err)
690 }
691 b = b[len(chunk):]
692 }
693 return consumed, nil
694}

Callers 1

TestPrefixedLineWriterFunction · 0.95

Calls 1

WriteMethod · 0.45

Tested by 1

TestPrefixedLineWriterFunction · 0.76