You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
774 B

  1. package erasure_coding
  2. import (
  3. "io"
  4. "os"
  5. "github.com/klauspost/reedsolomon"
  6. )
  7. const (
  8. DataShardsCount = 10
  9. ParityShardsCount = 4
  10. ErasureCodingLargeBlockSize = 1024 * 1024 * 1024 // 1GB
  11. ErasureCodingSmallBlockSize = 1024 * 1024 // 1MB
  12. )
  13. func encodeData(file *os.File, enc reedsolomon.Encoder, startOffset, blockSize int64, buffers [][]byte) error {
  14. // read data into buffers
  15. for i := 0; i < DataShardsCount; i++ {
  16. n, err := file.ReadAt(buffers[i], startOffset+blockSize*int64(i))
  17. if err != nil {
  18. if err != io.EOF {
  19. return err
  20. }
  21. }
  22. if n < len(buffers[i]) {
  23. for t := len(buffers[i]) - 1; t >= n; t-- {
  24. buffers[i][t] = 0
  25. }
  26. }
  27. }
  28. err := enc.Encode(buffers)
  29. if err != nil {
  30. return err
  31. }
  32. return nil
  33. }