readChunkWith read the encoded chunk from storage with a decoder.
(kvIdx uint64, chunkIdx uint64, decoder func([]byte, uint64) []byte)
| 128 | |
| 129 | // readChunkWith read the encoded chunk from storage with a decoder. |
| 130 | func (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. |
| 147 | func (ds *DataShard) ReadEncoded(kvIdx uint64, readLen int) ([]byte, error) { |
no test coverage detected