You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Victorique/vtqe/tools/split.go

62 lines
1.4 KiB
Go

5 years ago
package tools
import (
"fmt"
"strconv"
"b612.me/starainrt"
"b612.me/starlog"
"github.com/spf13/cobra"
)
var splitcmd = &cobra.Command{
Use: "split",
Short: "分割文件",
Long: "按字节或文件数分割文件",
Run: func(this *cobra.Command, args []string) {
var src, dst string
var num int
if len(args) == 3 {
src = args[0]
dst = args[1]
num, _ = strconv.Atoi(args[2])
} else {
src, _ = this.Flags().GetString("src")
dst, _ = this.Flags().GetString("dst")
num, _ = this.Flags().GetInt("num")
}
if !starainrt.Exists(src) {
starlog.Println("源文件不存在", "red", "b")
this.Help()
return
}
if num == 0 {
starlog.Println("参数num不合法", "red", "b")
this.Help()
return
}
crypto := new(starainrt.StarCrypto)
ok, _ := this.Flags().GetBool("byte")
err := crypto.SplitFile(src, dst, num, !ok, func(pect float64) {
if pect == 100 {
fmt.Println("文件已处理100.000000%")
} else {
fmt.Printf("文件已处理:%f%%\r", pect)
}
})
if err != nil {
starlog.Println(err.Error, "red", "")
}
},
}
func init() {
splitcmd.Flags().StringP("src", "s", "", "源文件地址")
splitcmd.Flags().StringP("dst", "d", "./split*.vicque", "目标文件地址,用*替换文件数字")
splitcmd.Flags().BoolP("byte", "b", false, "按byte分割")
splitcmd.Flags().IntP("num", "n", 0, "分割数/byte数")
Maincmd.AddCommand(splitcmd)
}