Adding initial split-file command

master
Frederick F. Kautz IV 10 years ago
parent b5d84790a2
commit f5010e1ee2
  1. BIN
      cmd/split-file/split-file
  2. 80
      cmd/split-file/split-file-options.go
  3. 32
      cmd/split-file/split-file.go
  4. 14
      cmd/split-file/split-file.md

Binary file not shown.

@ -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)
}

@ -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)
}

@ -0,0 +1,14 @@
% MINIO(1) Minio Manual
% Minio community
% January 2015
# NAME
split-file -
# SYNOPSIS
# DESCRIPTION
# EXAMPLES
# AUTHORS
Loading…
Cancel
Save