MCPcopy
hub / github.com/NVIDIA/aistore / Read

Method Read

transport/sendobj.go:416–459  ·  view source on GitHub ↗

lz4Stream //

(b []byte)

Source from the content-addressed store, hash-verified

414///////////////
415
416func (lz4s *lz4Stream) Read(b []byte) (n int, err error) {
417 var (
418 sendoff = &lz4s.s.sendoff
419 last = sendoff.obj.Hdr.isFin()
420 retry = 64 // insist on returning n > 0 (note that lz4 compresses /blocks/)
421 )
422 if lz4s.sgl.Len() > 0 {
423 lz4s.zw.Flush()
424 n, err = lz4s.sgl.Read(b)
425 if err == io.EOF { // reusing/rewinding this buf multiple times
426 err = nil
427 }
428 goto ex
429 }
430re:
431 n, err = lz4s.s.Read(b)
432 _, _ = lz4s.zw.Write(b[:n])
433 if last {
434 lz4s.zw.Flush()
435 retry = 0
436 } else if lz4s.s.sendoff.ins == inEOB || err != nil {
437 lz4s.zw.Flush()
438 retry = 0
439 }
440 n, _ = lz4s.sgl.Read(b)
441 if n == 0 {
442 if retry > 0 {
443 retry--
444 runtime.Gosched()
445 goto re
446 }
447 lz4s.zw.Flush()
448 n, _ = lz4s.sgl.Read(b)
449 }
450ex:
451 lz4s.s.stats.CompressedSize.Add(int64(n))
452 if lz4s.sgl.Len() == 0 {
453 lz4s.sgl.Reset()
454 }
455 if last && err == nil {
456 err = io.EOF
457 }
458 return
459}

Callers

nothing calls this directly

Calls 7

LenMethod · 0.65
FlushMethod · 0.65
AddMethod · 0.65
isFinMethod · 0.45
ReadMethod · 0.45
WriteMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected