MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / Read

Method Read

drivers/mega/util.go:45–76  ·  view source on GitHub ↗

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

(p []byte)

Source from the content-addressed store, hash-verified

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

Callers 5

ComputeTorrentFromReaderFunction · 0.45
PutMethod · 0.45
ComputeTorrentFromReaderFunction · 0.45
mergeUploadBlocksMethod · 0.45

Calls 3

getChunkMethod · 0.95
UnlockMethod · 0.65
ChunkLocationMethod · 0.45

Tested by

no test coverage detected