|
|
@ -14,22 +14,27 @@ func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, wri |
|
|
|
totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"]) |
|
|
|
totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"]) |
|
|
|
totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"]) |
|
|
|
totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"]) |
|
|
|
blockSize, _ := strconv.Atoi(donutMetadata["blockSize"]) |
|
|
|
blockSize, _ := strconv.Atoi(donutMetadata["blockSize"]) |
|
|
|
params, _ := erasure.ParseEncoderParams(8, 8, erasure.Cauchy) |
|
|
|
k, _ := strconv.Atoi(donutMetadata["erasureK"]) |
|
|
|
|
|
|
|
m, _ := strconv.Atoi(donutMetadata["erasureM"]) |
|
|
|
|
|
|
|
// TODO select technique properly
|
|
|
|
|
|
|
|
params, _ := erasure.ParseEncoderParams(uint8(k), uint8(m), erasure.Cauchy) |
|
|
|
encoder := erasure.NewEncoder(params) |
|
|
|
encoder := erasure.NewEncoder(params) |
|
|
|
for _, reader := range readers { |
|
|
|
for _, reader := range readers { |
|
|
|
defer reader.Close() |
|
|
|
defer reader.Close() |
|
|
|
} |
|
|
|
} |
|
|
|
for i := 0; i < totalChunks; i++ { |
|
|
|
for i := 0; i < totalChunks; i++ { |
|
|
|
|
|
|
|
curBlockSize := totalLeft |
|
|
|
|
|
|
|
if blockSize < totalLeft { |
|
|
|
|
|
|
|
curBlockSize = blockSize |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
curChunkSize := erasure.GetEncodedChunkLen(curBlockSize, uint8(k)) |
|
|
|
|
|
|
|
|
|
|
|
encodedBytes := make([][]byte, 16) |
|
|
|
encodedBytes := make([][]byte, 16) |
|
|
|
for i, reader := range readers { |
|
|
|
for i, reader := range readers { |
|
|
|
var bytesBuffer bytes.Buffer |
|
|
|
var bytesBuffer bytes.Buffer |
|
|
|
io.Copy(&bytesBuffer, reader) |
|
|
|
io.CopyN(&bytesBuffer, reader, int64(curChunkSize)) |
|
|
|
encodedBytes[i] = bytesBuffer.Bytes() |
|
|
|
encodedBytes[i] = bytesBuffer.Bytes() |
|
|
|
} |
|
|
|
} |
|
|
|
curBlockSize := totalLeft |
|
|
|
|
|
|
|
if blockSize < totalLeft { |
|
|
|
|
|
|
|
curBlockSize = blockSize |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
decodedData, err := encoder.Decode(encodedBytes, curBlockSize) |
|
|
|
decodedData, err := encoder.Decode(encodedBytes, curBlockSize) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
writer.CloseWithError(err) |
|
|
|
writer.CloseWithError(err) |
|
|
|