star/split/split.go
2023-04-04 14:11:09 +08:00

61 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package split
import (
"b612.me/starcrypto"
"fmt"
"strconv"
"b612.me/starlog"
"b612.me/staros"
"github.com/spf13/cobra"
)
var Cmd = &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 !staros.Exists(src) {
starlog.Errorln("源文件不存在")
this.Help()
return
}
if num == 0 {
starlog.Errorln("参数num不合法", "red")
this.Help()
return
}
ok, _ := this.Flags().GetBool("byte")
err := starcrypto.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.Errorln(err.Error)
}
},
}
func init() {
Cmd.Flags().StringP("src", "s", "", "源文件地址")
Cmd.Flags().StringP("dst", "d", "./split*.vicque", "目标文件地址,用*替换文件数字")
Cmd.Flags().BoolP("byte", "b", false, "按byte分割")
Cmd.Flags().IntP("num", "n", 0, "分割数/byte数")
}