MCPcopy Create free account
hub / github.com/antonmedv/gitmal / copyLinesFrom

Function copyLinesFrom

pkg/gitdiff/io.go:190–220  ·  view source on GitHub ↗

copyLinesFrom writes lines starting from line off in src to dst stopping at the end of src or at the first error. copyLinesFrom returns the number of lines written and any error.

(dst io.Writer, src LineReaderAt, off int64)

Source from the content-addressed store, hash-verified

188// the end of src or at the first error. copyLinesFrom returns the number of
189// lines written and any error.
190func copyLinesFrom(dst io.Writer, src LineReaderAt, off int64) (written int64, err error) {
191 buf := make([][]byte, lineBufferSize)
192ReadLoop:
193 for {
194 nr, rerr := src.ReadLinesAt(buf, off)
195 if nr > 0 {
196 for _, line := range buf[0:nr] {
197 nw, werr := dst.Write(line)
198 if nw > 0 {
199 written++
200 }
201 if werr != nil {
202 err = werr
203 break ReadLoop
204 }
205 if len(line) != nw {
206 err = io.ErrShortWrite
207 break ReadLoop
208 }
209 }
210 off += int64(nr)
211 }
212 if rerr != nil {
213 if rerr != io.EOF {
214 err = rerr
215 }
216 break
217 }
218 }
219 return written, err
220}

Callers 2

CloseMethod · 0.85
TestCopyLinesFromFunction · 0.85

Calls 2

WriteMethod · 0.80
ReadLinesAtMethod · 0.65

Tested by 1

TestCopyLinesFromFunction · 0.68