MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / Read

Method Read

drivers/halalcloud_open/utils.go:39–72  ·  view source on GitHub ↗

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

(p []byte)

Source from the content-addressed store, hash-verified

37
38// Read reads up to len(p) bytes into p.
39func (oo *openObject) Read(p []byte) (n int, err error) {
40 oo.mu.Lock()
41 defer oo.mu.Unlock()
42 if oo.closed {
43 return 0, fmt.Errorf("read on closed file")
44 }
45 // Skip data at the start if requested
46 for oo.skip > 0 {
47 //size := 1024 * 1024
48 _, size, err := oo.ChunkLocation(oo.id)
49 if err != nil {
50 return 0, err
51 }
52 if oo.skip < int64(size) {
53 break
54 }
55 oo.id++
56 oo.skip -= int64(size)
57 }
58 if len(oo.chunk) == 0 {
59 err = oo.getChunk(oo.ctx)
60 if err != nil {
61 return 0, err
62 }
63 if oo.skip > 0 {
64 oo.chunk = (oo.chunk)[oo.skip:]
65 oo.skip = 0
66 }
67 }
68 n = copy(p, oo.chunk)
69 oo.shaTemp.Write(p[:n])
70 oo.chunk = (oo.chunk)[n:]
71 return n, nil
72}
73
74// Close closed the file - MAC errors are reported here
75func (oo *openObject) Close() (err error) {

Callers 1

putMethod · 0.45

Calls 4

ChunkLocationMethod · 0.95
getChunkMethod · 0.95
UnlockMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected