MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / read

Function read

cmd/cql-fuse/block.go:193–222  ·  view source on GitHub ↗

read returns the data [from, to). Requires: to > from and [to, from) is contained in the file.

(e sqlExecutor, inodeID, from, to uint64)

Source from the content-addressed store, hash-verified

191// read returns the data [from, to).
192// Requires: to > from and [to, from) is contained in the file.
193func read(e sqlExecutor, inodeID, from, to uint64) ([]byte, error) {
194 readRange := newBlockRange(from, to-from)
195 end := readRange.last
196 if readRange.lastLength == 0 {
197 end--
198 }
199
200 blockInfos, err := getBlocksBetween(e, inodeID, readRange.start, end)
201 if err != nil {
202 return nil, err
203 }
204 if len(blockInfos) != end-readRange.start+1 {
205 return nil, fmt.Errorf("wrong number of blocks, asked for [%d-%d], got %d back",
206 readRange.start, end, len(blockInfos))
207 }
208
209 if readRange.lastLength != 0 {
210 // We have a last partial block, truncate it.
211 last := len(blockInfos) - 1
212 blockInfos[last].data = blockInfos[last].data[:readRange.lastLength]
213 }
214 blockInfos[0].data = blockInfos[0].data[readRange.startOffset:]
215
216 var data []byte
217 for _, b := range blockInfos {
218 data = append(data, b.data...)
219 }
220
221 return data, nil
222}
223
224// write commits data to the blocks starting at 'offset'
225// Amount of data to write must be non-zero.

Callers 5

BenchmarkStorageFunction · 0.85
ReadMethod · 0.85
tryGrowFunction · 0.85
tryShrinkFunction · 0.85
TestReadWriteBlocksFunction · 0.85

Calls 3

newBlockRangeFunction · 0.85
getBlocksBetweenFunction · 0.85
ErrorfMethod · 0.80

Tested by 4

BenchmarkStorageFunction · 0.68
tryGrowFunction · 0.68
tryShrinkFunction · 0.68
TestReadWriteBlocksFunction · 0.68