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

Method readChunkWith

ethstorage/data_shard.go:130–144  ·  view source on GitHub ↗

readChunkWith read the encoded chunk from storage with a decoder.

(kvIdx uint64, chunkIdx uint64, decoder func([]byte, uint64) []byte)

Source from the content-addressed store, hash-verified

128
129// readChunkWith read the encoded chunk from storage with a decoder.
130func (ds *DataShard) readChunkWith(kvIdx uint64, chunkIdx uint64, decoder func([]byte, uint64) []byte) ([]byte, error) {
131 if !ds.Contains(kvIdx) {
132 return nil, fmt.Errorf("kv not found")
133 }
134 if chunkIdx >= ds.chunksPerKv {
135 return nil, fmt.Errorf("chunkIdx out of range, chunkIdx: %d vs chunksPerKv %d", chunkIdx, ds.chunksPerKv)
136 }
137 idx := kvIdx*ds.chunksPerKv + chunkIdx
138 data, err := ds.readChunk(idx, int(ds.chunkSize))
139 if err != nil {
140 return nil, err
141 }
142 data = decoder(data, idx)
143 return data, nil
144}
145
146// ReadEncoded read the encoded data from storage and return it.
147func (ds *DataShard) ReadEncoded(kvIdx uint64, readLen int) ([]byte, error) {

Callers 2

ReadChunkEncodedMethod · 0.95
ReadChunkMethod · 0.95

Calls 2

ContainsMethod · 0.95
readChunkMethod · 0.95

Tested by

no test coverage detected