diff --git a/cmd/split-file/split-file b/cmd/split-file/split-file new file mode 100755 index 000000000..0170b48da Binary files /dev/null and b/cmd/split-file/split-file differ diff --git a/cmd/split-file/split-file-options.go b/cmd/split-file/split-file-options.go new file mode 100644 index 000000000..71e417c48 --- /dev/null +++ b/cmd/split-file/split-file-options.go @@ -0,0 +1,80 @@ +/* + * Mini Object Storage, (C) 2014 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "io" + "log" + "os" + "path" + + "github.com/codegangsta/cli" + "github.com/minio-io/minio/pkg/split" + "github.com/minio-io/minio/pkg/strbyteconv" +) + +var Options = []cli.Command{ + Split, + Merge, +} + +var Split = cli.Command{ + Name: "split", + Usage: "Describes how large each split should be", + Description: "", + Action: doFileSplit, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "size,s", + Value: "2M", + Usage: "", + }, + }, +} + +var Merge = cli.Command{ + Name: "merge", + Usage: "Describes how large each split should be", + Description: "", + Action: doFileMerge, +} + +func doFileSplit(c *cli.Context) { + chunkSize, err := strbyteconv.StringToBytes(c.String("size")) + if err != nil { + log.Fatal(err) + } + err = split.SplitFileWithPrefix(c.Args().Get(0), chunkSize, c.Args().Get(1)) + if err != nil { + // TODO cleanup? + log.Fatal(err) + } +} + +func doFileMerge(c *cli.Context) { + prefix := c.Args().Get(0) + output := c.Args().Get(1) + prefix = path.Clean(prefix) + log.Println(path.Dir(prefix), path.Base(prefix)) + reader := split.JoinFiles(path.Dir(prefix), path.Base(prefix)) + file, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + log.Fatal(err) + } + defer file.Close() + io.Copy(file, reader) +} diff --git a/cmd/split-file/split-file.go b/cmd/split-file/split-file.go new file mode 100644 index 000000000..f64612d77 --- /dev/null +++ b/cmd/split-file/split-file.go @@ -0,0 +1,32 @@ +/* + * Mini Object Storage, (C) 2014 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "os" + + "github.com/codegangsta/cli" +) + +func main() { + app := cli.NewApp() + app.Name = "split-file" + app.Usage = "" + app.Commands = Options + app.Author = "Minio" + app.Run(os.Args) +} diff --git a/cmd/split-file/split-file.md b/cmd/split-file/split-file.md new file mode 100644 index 000000000..d24a2b629 --- /dev/null +++ b/cmd/split-file/split-file.md @@ -0,0 +1,14 @@ + +% MINIO(1) Minio Manual +% Minio community +% January 2015 +# NAME +split-file - + +# SYNOPSIS + +# DESCRIPTION + +# EXAMPLES + +# AUTHORS