MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / ReadBody

Method ReadBody

internal/caches/reader_memory.go:83–116  ·  view source on GitHub ↗
(buf []byte, callback ReaderFunc)

Source from the content-addressed store, hash-verified

81}
82
83func (this *MemoryReader) ReadBody(buf []byte, callback ReaderFunc) error {
84 l := len(buf)
85 if l == 0 {
86 return errors.New("using empty buffer")
87 }
88
89 size := len(this.item.BodyValue)
90 offset := 0
91 for {
92 left := size - offset
93 if l <= left {
94 copy(buf, this.item.BodyValue[offset:offset+l])
95 goNext, e := callback(l)
96 if e != nil {
97 return e
98 }
99 if !goNext {
100 break
101 }
102 } else {
103 copy(buf, this.item.BodyValue[offset:])
104 _, e := callback(left)
105 if e != nil {
106 return e
107 }
108 break
109 }
110 offset += l
111 if offset >= size {
112 break
113 }
114 }
115 return nil
116}
117
118func (this *MemoryReader) Read(buf []byte) (n int, err error) {
119 bufLen := len(buf)

Callers 1

TestMemoryReader_BodyFunction · 0.95

Calls

no outgoing calls

Tested by 1

TestMemoryReader_BodyFunction · 0.76