MCPcopy
hub / github.com/rclone/rclone / Read

Method Read

backend/mega/mega.go:1083–1114  ·  view source on GitHub ↗

Read reads up to len(p) bytes into p.

(p []byte)

Source from the content-addressed store, hash-verified

1081
1082// Read reads up to len(p) bytes into p.
1083func (oo *openObject) Read(p []byte) (n int, err error) {
1084 oo.mu.Lock()
1085 defer oo.mu.Unlock()
1086 if oo.closed {
1087 return 0, errors.New("read on closed file")
1088 }
1089 // Skip data at the start if requested
1090 for oo.skip > 0 {
1091 _, size, err := oo.d.ChunkLocation(oo.id)
1092 if err != nil {
1093 return 0, err
1094 }
1095 if oo.skip < int64(size) {
1096 break
1097 }
1098 oo.id++
1099 oo.skip -= int64(size)
1100 }
1101 if len(oo.chunk) == 0 {
1102 err = oo.getChunk(oo.ctx)
1103 if err != nil {
1104 return 0, err
1105 }
1106 if oo.skip > 0 {
1107 oo.chunk = oo.chunk[oo.skip:]
1108 oo.skip = 0
1109 }
1110 }
1111 n = copy(p, oo.chunk)
1112 oo.chunk = oo.chunk[n:]
1113 return n, nil
1114}
1115
1116// Close closed the file - MAC errors are reported here
1117func (oo *openObject) Close() (err error) {

Callers

nothing calls this directly

Calls 4

getChunkMethod · 0.95
copyStruct · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected