MCPcopy Create free account
hub / github.com/ethstorage/es-node / ReadWithMeta

Method ReadWithMeta

ethstorage/data_shard.go:170–187  ·  view source on GitHub ↗

Read the encoded data from storage and decode it.

(kvIdx uint64, readLen int)

Source from the content-addressed store, hash-verified

168
169// Read the encoded data from storage and decode it.
170func (ds *DataShard) ReadWithMeta(kvIdx uint64, readLen int) ([]byte, []byte, error) {
171 commit, err := ds.ReadMeta(kvIdx)
172 if err != nil {
173 return nil, nil, err
174 }
175 bs, err := ds.readWith(kvIdx, int(ds.kvSize), func(cdata []byte, chunkIdx uint64) []byte {
176 encodeKey := calcEncodeKey(common.BytesToHash(commit), chunkIdx, ds.dataFiles[0].miner)
177 return decodeChunk(ds.chunkSize, cdata, ds.dataFiles[0].encodeType, encodeKey)
178 })
179 if err != nil {
180 return nil, nil, err
181 }
182
183 if err = checkCommit(common.BytesToHash(commit), bs); err != nil {
184 return nil, nil, err
185 }
186 return bs[0:readLen], commit, nil
187}
188
189// readWith read the encoded data from storage with a decoder.
190func (ds *DataShard) readWith(kvIdx uint64, readLen int, decoder func([]byte, uint64) []byte) ([]byte, error) {

Callers 2

TryReadWithMetaMethod · 0.80
runKVReadFunction · 0.80

Calls 5

ReadMetaMethod · 0.95
readWithMethod · 0.95
calcEncodeKeyFunction · 0.85
decodeChunkFunction · 0.85
checkCommitFunction · 0.85

Tested by

no test coverage detected