2014-11-30 07:48:37 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/minio-io/minio/pkgs/erasure"
|
|
|
|
)
|
|
|
|
|
|
|
|
func encode(c *cli.Context) {
|
|
|
|
// check if minio-encode called without parameters
|
|
|
|
if len(c.Args()) != 1 {
|
|
|
|
cli.ShowCommandHelp(c, "encode")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-01 07:18:02 +01:00
|
|
|
config, err := parseInput(c)
|
2014-11-30 07:48:37 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get file
|
2014-12-01 07:18:02 +01:00
|
|
|
inputFile, err := os.Open(config.input)
|
2014-11-30 07:48:37 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// read file
|
|
|
|
input, err := ioutil.ReadAll(inputFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up encoder
|
2014-12-01 07:18:02 +01:00
|
|
|
erasureParameters, _ := erasure.ParseEncoderParams(config.k, config.m, erasure.CAUCHY)
|
2014-11-30 07:48:37 +01:00
|
|
|
// encode data
|
|
|
|
encodedData, length := erasure.Encode(input, erasureParameters)
|
|
|
|
|
|
|
|
// write encoded data out
|
|
|
|
for key, data := range encodedData {
|
2014-12-01 07:18:02 +01:00
|
|
|
ioutil.WriteFile(config.output+"."+strconv.Itoa(key), data, 0600)
|
2014-11-30 07:48:37 +01:00
|
|
|
}
|
2014-12-01 07:18:02 +01:00
|
|
|
ioutil.WriteFile(config.output+".length", []byte(strconv.Itoa(length)), 0600)
|
2014-11-30 07:48:37 +01:00
|
|
|
}
|