XL: Fix GetObject erasure decode issues. (#1793)

This commit is contained in:
Harshavardhana
2016-05-29 15:38:14 -07:00
parent 5e8de786b3
commit a4a0ea605b
12 changed files with 154 additions and 146 deletions

View File

@@ -16,13 +16,31 @@
package main
import "github.com/klauspost/reedsolomon"
// getDataBlocks - fetches the data block only part of the input encoded blocks.
func getDataBlocks(enBlocks [][]byte, dataBlocks int, curBlockSize int) (data []byte) {
for _, block := range enBlocks[:dataBlocks] {
data = append(data, block...)
func getDataBlocks(enBlocks [][]byte, dataBlocks int, curBlockSize int) (data []byte, err error) {
if len(enBlocks) < dataBlocks {
return nil, reedsolomon.ErrTooFewShards
}
data = data[:curBlockSize]
return data
size := 0
blocks := enBlocks[:dataBlocks]
for _, block := range blocks {
size += len(block)
}
if size < curBlockSize {
return nil, reedsolomon.ErrShortData
}
write := curBlockSize
for _, block := range blocks {
if write < len(block) {
data = append(data, block[:write]...)
return data, nil
}
data = append(data, block...)
write -= len(block)
}
return data, nil
}
// checkBlockSize return the size of a single block.