MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / ReadBody

Method ReadBody

internal/caches/reader_file.go:218–262  ·  view source on GitHub ↗
(buf []byte, callback ReaderFunc)

Source from the content-addressed store, hash-verified

216}
217
218func (this *FileReader) ReadBody(buf []byte, callback ReaderFunc) error {
219 if this.bodySize == 0 {
220 return nil
221 }
222
223 var isOk = false
224
225 defer func() {
226 if !isOk {
227 _ = this.discard()
228 }
229 }()
230
231 var offset = this.bodyOffset
232
233 // 开始读Body部分
234 _, err := this.fp.Seek(offset, io.SeekStart)
235 if err != nil {
236 return err
237 }
238
239 for {
240 n, err := this.fp.Read(buf)
241 if n > 0 {
242 goNext, e := callback(n)
243 if e != nil {
244 isOk = true
245 return e
246 }
247 if !goNext {
248 break
249 }
250 }
251 if err != nil {
252 if err != io.EOF {
253 return err
254 }
255 break
256 }
257 }
258
259 isOk = true
260
261 return nil
262}
263
264func (this *FileReader) Read(buf []byte) (n int, err error) {
265 if this.bodySize == 0 {

Callers 1

TestFileReaderFunction · 0.95

Calls 3

discardMethod · 0.95
SeekMethod · 0.80
ReadMethod · 0.65

Tested by 1

TestFileReaderFunction · 0.76