MCPcopy Create free account
hub / github.com/valyala/bytebufferpool / ReadFrom

Method ReadFrom

bytebuffer.go:27–56  ·  view source on GitHub ↗

ReadFrom implements io.ReaderFrom. The function appends all the data read from r to b.

(r io.Reader)

Source from the content-addressed store, hash-verified

25//
26// The function appends all the data read from r to b.
27func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error) {
28 p := b.B
29 nStart := int64(len(p))
30 nMax := int64(cap(p))
31 n := nStart
32 if nMax == 0 {
33 nMax = 64
34 p = make([]byte, nMax)
35 } else {
36 p = p[:nMax]
37 }
38 for {
39 if n == nMax {
40 nMax *= 2
41 bNew := make([]byte, nMax)
42 copy(bNew, p)
43 p = bNew
44 }
45 nn, err := r.Read(p[n:])
46 n += int64(nn)
47 if err != nil {
48 b.B = p[:n]
49 n -= nStart
50 if err == io.EOF {
51 return n, nil
52 }
53 return n, err
54 }
55 }
56}
57
58// WriteTo implements io.WriterTo.
59func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {

Callers 1

TestByteBufferReadFromFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestByteBufferReadFromFunction · 0.64