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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.StdPrintln(0, starlog.RED, "源文件不存在")
this.Help()
return
}
if num == 0 {
starlog.StdPrintln(0, starlog.RED, "参数num不合法", "red")
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.StdPrintln(0, starlog.RED, err.Error)
}
},
}
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)
}