|
|
@ -5,7 +5,6 @@ import ( |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli" |
|
|
|
"github.com/codegangsta/cli" |
|
|
|
"github.com/minio-io/minio/pkgs/erasure" |
|
|
|
"github.com/minio-io/minio/pkgs/erasure" |
|
|
@ -18,33 +17,13 @@ func encode(c *cli.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get input path
|
|
|
|
config, err := parseInput(c) |
|
|
|
inputFilePath := c.Args().Get(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get output path
|
|
|
|
|
|
|
|
outputFilePath := inputFilePath |
|
|
|
|
|
|
|
if c.String("output") != "" { |
|
|
|
|
|
|
|
outputFilePath = c.String("output") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protectionLevel := c.String("protection-level") |
|
|
|
|
|
|
|
protectionLevelSplit := strings.Split(protectionLevel, ",") |
|
|
|
|
|
|
|
if len(protectionLevelSplit) != 2 { |
|
|
|
|
|
|
|
log.Fatal("Malformed input for protection-level") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k, err := strconv.Atoi(protectionLevelSplit[0]) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m, err := strconv.Atoi(protectionLevelSplit[1]) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal(err) |
|
|
|
log.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get file
|
|
|
|
// get file
|
|
|
|
inputFile, err := os.Open(inputFilePath) |
|
|
|
inputFile, err := os.Open(config.input) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal(err) |
|
|
|
log.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
@ -56,13 +35,13 @@ func encode(c *cli.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set up encoder
|
|
|
|
// set up encoder
|
|
|
|
erasureParameters, _ := erasure.ParseEncoderParams(k, m, erasure.CAUCHY) |
|
|
|
erasureParameters, _ := erasure.ParseEncoderParams(config.k, config.m, erasure.CAUCHY) |
|
|
|
// encode data
|
|
|
|
// encode data
|
|
|
|
encodedData, length := erasure.Encode(input, erasureParameters) |
|
|
|
encodedData, length := erasure.Encode(input, erasureParameters) |
|
|
|
|
|
|
|
|
|
|
|
// write encoded data out
|
|
|
|
// write encoded data out
|
|
|
|
for key, data := range encodedData { |
|
|
|
for key, data := range encodedData { |
|
|
|
ioutil.WriteFile(outputFilePath+"."+strconv.Itoa(key), data, 0600) |
|
|
|
ioutil.WriteFile(config.output+"."+strconv.Itoa(key), data, 0600) |
|
|
|
} |
|
|
|
} |
|
|
|
ioutil.WriteFile(outputFilePath+".length", []byte(strconv.Itoa(length)), 0600) |
|
|
|
ioutil.WriteFile(config.output+".length", []byte(strconv.Itoa(length)), 0600) |
|
|
|
} |
|
|
|
} |
|
|
|