Read the encoded data from storage and decode it.
(kvIdx uint64, readLen int)
| 168 | |
| 169 | // Read the encoded data from storage and decode it. |
| 170 | func (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. |
| 190 | func (ds *DataShard) readWith(kvIdx uint64, readLen int, decoder func([]byte, uint64) []byte) ([]byte, error) { |
no test coverage detected