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

Method readWith

ethstorage/data_shard.go:190–216  ·  view source on GitHub ↗

readWith read the encoded data from storage with a decoder.

(kvIdx uint64, readLen int, decoder func([]byte, uint64) []byte)

Source from the content-addressed store, hash-verified

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) {
191 if !ds.Contains(kvIdx) {
192 return nil, fmt.Errorf("kv not found")
193 }
194 if readLen > int(ds.kvSize) {
195 return nil, fmt.Errorf("read len too large")
196 }
197 var data []byte
198 for i := uint64(0); i < ds.chunksPerKv; i++ {
199 if readLen == 0 {
200 break
201 }
202
203 chunkReadLen := min(readLen, int(ds.chunkSize))
204 readLen = readLen - chunkReadLen
205
206 chunkIdx := kvIdx*ds.chunksPerKv + i
207 cdata, err := ds.readChunk(chunkIdx, chunkReadLen)
208 if err != nil {
209 return nil, err
210 }
211
212 cdata = decoder(cdata, chunkIdx)
213 data = append(data, cdata...)
214 }
215 return data, nil
216}
217
218func (ds *DataShard) ReadSample(sampleIdx uint64) (common.Hash, error) {
219

Callers 3

ReadEncodedMethod · 0.95
ReadMethod · 0.95
ReadWithMetaMethod · 0.95

Calls 2

ContainsMethod · 0.95
readChunkMethod · 0.95

Tested by

no test coverage detected